Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
f697b4b4
Commit
f697b4b4
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Add failed auth ratelimiting to UIA
parent
541f1b92
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/handlers/auth.py
+32
-1
32 additions, 1 deletion
synapse/handlers/auth.py
with
32 additions
and
1 deletion
synapse/handlers/auth.py
+
32
−
1
View file @
f697b4b4
...
...
@@ -35,6 +35,7 @@ from synapse.api.errors import (
SynapseError
,
UserDeactivatedError
,
)
from
synapse.api.ratelimiting
import
Ratelimiter
from
synapse.handlers.ui_auth
import
INTERACTIVE_AUTH_CHECKERS
from
synapse.handlers.ui_auth.checkers
import
UserInteractiveAuthChecker
from
synapse.logging.context
import
defer_to_thread
...
...
@@ -101,6 +102,10 @@ class AuthHandler(BaseHandler):
login_types
.
append
(
t
)
self
.
_supported_login_types
=
login_types
# Ratelimiter for failed auth during UIA. Uses same ratelimit config
# as per `rc_login.failed_attempts`.
self
.
_failed_uia_attempts_ratelimiter
=
Ratelimiter
()
self
.
_clock
=
self
.
hs
.
get_clock
()
@defer.inlineCallbacks
...
...
@@ -129,12 +134,38 @@ class AuthHandler(BaseHandler):
AuthError if the client has completed a login flow, and it gives
a different user to `requester`
LimitExceededError if the ratelimiter
'
s failed requests count for this
user is too high too proceed
"""
user_id
=
requester
.
user
.
to_string
()
# Check if we should be ratelimited due to too many previous failed attempts
self
.
_failed_uia_attempts_ratelimiter
.
ratelimit
(
user_id
,
time_now_s
=
self
.
_clock
.
time
(),
rate_hz
=
self
.
hs
.
config
.
rc_login_failed_attempts
.
per_second
,
burst_count
=
self
.
hs
.
config
.
rc_login_failed_attempts
.
burst_count
,
update
=
False
,
)
# build a list of supported flows
flows
=
[[
login_type
]
for
login_type
in
self
.
_supported_login_types
]
result
,
params
,
_
=
yield
self
.
check_auth
(
flows
,
request_body
,
clientip
)
try
:
result
,
params
,
_
=
yield
self
.
check_auth
(
flows
,
request_body
,
clientip
)
except
LoginError
:
# Update the ratelimite to say we failed (`can_do_action` doesn't raise).
self
.
_failed_uia_attempts_ratelimiter
.
can_do_action
(
user_id
,
time_now_s
=
self
.
_clock
.
time
(),
rate_hz
=
self
.
hs
.
config
.
rc_login_failed_attempts
.
per_second
,
burst_count
=
self
.
hs
.
config
.
rc_login_failed_attempts
.
burst_count
,
update
=
True
,
)
raise
# find the completed login type
for
login_type
in
self
.
_supported_login_types
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment