Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4be4ea0
Add debug log when `HMAC incorrect`
MadLittleMods May 23, 2025
7feedb9
Fix order
MadLittleMods May 23, 2025
944800d
Remove extra testing log
MadLittleMods May 23, 2025
8e45c6f
Add changelog
MadLittleMods May 23, 2025
95a084e
Add to sensitive part of logging template for Docker
MadLittleMods May 23, 2025
e079104
Document dangers of `DEBUG` level logging
MadLittleMods May 23, 2025
a0ada44
Merge branch 'develop' into madlittlemods/debug-hmac-incorrect
MadLittleMods Jun 6, 2025
1aac00f
Not fully working correctly: `ExplicitlyConfiguredLogger` via filters
MadLittleMods Jun 6, 2025
7e5ef26
Working `ExplicitlyConfiguredLogger` but not a great setup experience
MadLittleMods Jun 6, 2025
fea75ae
Better comments
MadLittleMods Jun 6, 2025
7f4a06b
Revert "Document dangers of `DEBUG` level logging"
MadLittleMods Jun 6, 2025
6b13fbd
Revert "Add to sensitive part of logging template for Docker"
MadLittleMods Jun 6, 2025
b44e5d7
Remove debug logs
MadLittleMods Jun 6, 2025
57da8ba
Fix typo
MadLittleMods Jun 6, 2025
34c101b
Merge branch 'develop' into madlittlemods/debug-hmac-incorrect
MadLittleMods Jun 17, 2025
5735d66
Merge branch 'develop' into madlittlemods/debug-hmac-incorrect
MadLittleMods Jun 20, 2025
3cf7dbf
Merge branch 'develop' into madlittlemods/debug-hmac-incorrect
MadLittleMods Jul 21, 2025
b1e96ae
Override `isEnabledFor` so that we can use it accurately
MadLittleMods Jul 22, 2025
19aeeee
No need to add a filter with `isEnabledFor`
MadLittleMods Jul 22, 2025
b8bc1e3
Add `ExplicitlyConfiguredLoggerTestCase`
MadLittleMods Jul 22, 2025
3707374
Add tests for `isEnabledFor`
MadLittleMods Jul 22, 2025
5b1020c
Workaround `assertNoLogs` not beinga available
MadLittleMods Jul 22, 2025
78e29dc
Remove unused change
MadLittleMods Jul 22, 2025
c00a3e7
Remove unused boilerplate
MadLittleMods Jul 22, 2025
5716db6
Merge branch 'develop' into madlittlemods/debug-hmac-incorrect
MadLittleMods Jul 22, 2025
e2e0e0c
Fix matching pair back-ticks typo in test log
MadLittleMods Jul 22, 2025
b15bf3e
Merge branch 'develop' into madlittlemods/debug-hmac-incorrect
MadLittleMods Jul 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18474.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add debug logging for HMAC digest verification failures when using the admin API to register users.
Comment thread
MadLittleMods marked this conversation as resolved.
4 changes: 4 additions & 0 deletions docker/conf/log.config
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ loggers:
# beware: increasing this to DEBUG will make synapse log sensitive
# information such as access tokens.
level: INFO
synapse.rest.admin.users.registration_debug:
# beware: increasing this to DEBUG will make synapse log sensitive
# information such as passwords and `registration_shared_secret`.
level: INFO
{% endif %}

{% if SYNAPSE_LOG_TESTING %}
Expand Down
3 changes: 3 additions & 0 deletions docs/usage/configuration/logging_sample_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ It should be named `<SERVERNAME>.log.config` by default.
Hint: If you're looking for a guide on what each of the fields in the "Processed request" log lines mean,
see [Request log format](../administration/request_log.md).

Warn: Logging at the `DEBUG` level is very verbose and will include sensitive
information such as access tokens, passwords, and secrets.

```yaml
{{#include ../../sample_log_config.yaml}}
```
15 changes: 15 additions & 0 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@

logger = logging.getLogger(__name__)

user_registration_debug_logger = logging.getLogger(
"synapse.rest.admin.users.registration_debug"
Comment thread
anoadragon453 marked this conversation as resolved.
)
"""
A logger for debugging the user registration process. This is separate from the main
logger as it logs sensitive information such as passwords and `registration_shared_secret`.
"""


class UsersRestServletV2(RestServlet):
PATTERNS = admin_patterns("/users$", "v2")
Expand Down Expand Up @@ -633,6 +641,13 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
want_mac = want_mac_builder.hexdigest()

if not hmac.compare_digest(want_mac.encode("ascii"), got_mac.encode("ascii")):
user_registration_debug_logger.debug(
"UserRegisterServlet: Incorrect HMAC digest: actual=%s, expected=%s, registration_shared_secret=%s, body=%s",
got_mac,
want_mac,
self.hs.config.registration.registration_shared_secret,
body,
)
Comment thread
MadLittleMods marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Contributor Author

@MadLittleMods MadLittleMods Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an update on the root cause on why we were seeing of HMAC incorrect error, @devonh found that the file for the registration_shared_secret_path itself had an incorrect/unexpected value.

Basically, we're running into the default Synapse behavior (of creating the file and secret if it doesn't exist) masking our deployment race condition where we would start up Synapse before the registration_shared_secret_path file was put in place:

registration_shared_secret_path

[...]

If this file does not exist, Synapse will create a new shared secret on startup and store it in this file.

-- Synapse config docs

raise SynapseError(HTTPStatus.FORBIDDEN, "HMAC incorrect")

should_issue_refresh_token = body.get("refresh_token", False)
Expand Down
Loading