Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
c0673c50
Commit
c0673c50
authored
10 years ago
by
Paul "LeoNerd" Evans
Browse files
Options
Downloads
Plain Diff
Merge branch 'jira/SYN-60' into develop
parents
7d94913e
c03176af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/config/captcha.py
+6
-1
6 additions, 1 deletion
synapse/config/captcha.py
synapse/rest/register.py
+38
-5
38 additions, 5 deletions
synapse/rest/register.py
with
44 additions
and
6 deletions
synapse/config/captcha.py
+
6
−
1
View file @
c0673c50
...
...
@@ -24,6 +24,7 @@ class CaptchaConfig(Config):
self
.
captcha_ip_origin_is_x_forwarded
=
(
args
.
captcha_ip_origin_is_x_forwarded
)
self
.
captcha_bypass_secret
=
args
.
captcha_bypass_secret
@classmethod
def
add_arguments
(
cls
,
parser
):
...
...
@@ -43,4 +44,8 @@ class CaptchaConfig(Config):
"
--captcha_ip_origin_is_x_forwarded
"
,
type
=
bool
,
default
=
False
,
help
=
"
When checking captchas, use the X-Forwarded-For (XFF) header
"
+
"
as the client IP and not the actual client IP.
"
)
\ No newline at end of file
)
group
.
add_argument
(
"
--captcha_bypass_secret
"
,
type
=
str
,
help
=
"
A secret key used to bypass the captcha test entirely.
"
)
This diff is collapsed.
Click to expand it.
synapse/rest/register.py
+
38
−
5
View file @
c0673c50
...
...
@@ -21,6 +21,8 @@ from synapse.api.constants import LoginType
from
base
import
RestServlet
,
client_path_pattern
import
synapse.util.stringutils
as
stringutils
from
hashlib
import
sha1
import
hmac
import
json
import
logging
import
urllib
...
...
@@ -142,6 +144,38 @@ class RegisterRestServlet(RestServlet):
if
not
self
.
hs
.
config
.
enable_registration_captcha
:
raise
SynapseError
(
400
,
"
Captcha not required.
"
)
yield
self
.
_check_recaptcha
(
request
,
register_json
,
session
)
session
[
LoginType
.
RECAPTCHA
]
=
True
# mark captcha as done
self
.
_save_session
(
session
)
defer
.
returnValue
({
"
next
"
:
[
LoginType
.
PASSWORD
,
LoginType
.
EMAIL_IDENTITY
]
})
@defer.inlineCallbacks
def
_check_recaptcha
(
self
,
request
,
register_json
,
session
):
if
(
"
captcha_bypass_hmac
"
in
register_json
and
self
.
hs
.
config
.
captcha_bypass_secret
):
if
"
user
"
not
in
register_json
:
raise
SynapseError
(
400
,
"
Captcha bypass needs
'
user
'"
)
want
=
hmac
.
new
(
key
=
self
.
hs
.
config
.
captcha_bypass_secret
,
msg
=
register_json
[
"
user
"
],
digestmod
=
sha1
,
).
hexdigest
()
# str() because otherwise hmac complains that 'unicode' does not
# have the buffer interface
got
=
str
(
register_json
[
"
captcha_bypass_hmac
"
])
if
hmac
.
compare_digest
(
want
,
got
):
session
[
"
user
"
]
=
register_json
[
"
user
"
]
defer
.
returnValue
(
None
)
else
:
raise
SynapseError
(
400
,
"
Captcha bypass HMAC incorrect
"
,
errcode
=
Codes
.
CAPTCHA_NEEDED
)
challenge
=
None
user_response
=
None
try
:
...
...
@@ -166,11 +200,6 @@ class RegisterRestServlet(RestServlet):
challenge
,
user_response
)
session
[
LoginType
.
RECAPTCHA
]
=
True
# mark captcha as done
self
.
_save_session
(
session
)
defer
.
returnValue
({
"
next
"
:
[
LoginType
.
PASSWORD
,
LoginType
.
EMAIL_IDENTITY
]
})
@defer.inlineCallbacks
def
_do_email_identity
(
self
,
request
,
register_json
,
session
):
...
...
@@ -195,6 +224,10 @@ class RegisterRestServlet(RestServlet):
# captcha should've been done by this stage!
raise
SynapseError
(
400
,
"
Captcha is required.
"
)
if
(
"
user
"
in
session
and
"
user
"
in
register_json
and
session
[
"
user
"
]
!=
register_json
[
"
user
"
]):
raise
SynapseError
(
400
,
"
Cannot change user ID during registration
"
)
password
=
register_json
[
"
password
"
].
encode
(
"
utf-8
"
)
desired_user_id
=
(
register_json
[
"
user
"
].
encode
(
"
utf-8
"
)
if
"
user
"
in
register_json
else
None
)
...
...
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