Repository navigation
fix: model Django's CSRF token and reversed URLs as values attackers cannot shape - #133
Merged
Merged
Conversation
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #132. This is the third model fix that comes before the stricter guard rule from #98, covering the healthchecks false positives that rule would otherwise raise to HIGH. It is independent of #129 and #131, apart from the shared
CHANGELOGspot.Change
django.middleware.csrf.get_tokenbecomes a sanitizer for every kind. It returns_mask_cipher_secret(...), built fromCSRF_ALLOWED_CHARS(ASCII letters and digits), and an incoming cookie of another shape is rejected by_check_token_formatfirst (Django 5.2middleware/csrf.py).django.urls.reverseandreverse_lazy(and theirdjango.urls.basespellings) become sanitizers forREDIRECTonly. The result is a path of the project's URL configuration: arguments are quoted, a query goes after?, andescape_leading_slashesrules out//host(Django 5.2urls/resolvers.py,urls/base.py).'is left unquoted, since it is an RFC 3986 sub-delimiter, so other kinds still flow. A test keeps a SQL injection throughreversereported.Snapshot changes, reviewed (healthchecks only)
hc/accounts/views.py:214 xss(signup_csrf)HttpResponse(csrf.get_token(request)): an alphanumeric token.hc/accounts/views.py:142 open-redirect(_check_2fa)redirect(reverse(route, query=query)):nextonly ends up URL-encoded in the query string.hc/front/views.py:553, 574, 670 open-redirecturl = reverse("hc-checks", args=[...]); url += _get_referer_qs(request); redirect(url). The taint came throughargs, from the view's parameters. The target starts with a local path, so no suffix can change the host.hc/front/views.py:1115 open-redirect(copy)redirect(reverse("hc-details", args=[copied.code], query={"copied": 1})).A correction to what I said in #98: healthchecks lines 170 and 281 do not reach the redirect guarded by
_allow_redirect(line 115). They reach thisreverseredirect at line 142._allow_redirectonly concerns line 115, a hotspot that stays one; declaring it as a validator is tracked separately.Not fixed here: the findings at lines 170 and 281. They are reported at the callers, through
_check_2fa, and a sanitizer inside a project function does not protect its callers' flows. Function summaries record which parameters reach which external calls, not the models applied along the way. A helper doingHttpResponse(escape(value))has the same limit. Tracked in #134.Verification
pytest: 1005 passed.ruff check src testsandmypyare clean.pytest -m regressionunder Python 3.12: 19 passed. Onlyhealthchecks.jsonchanged, by the six findings above.reverseand a redirect to raw input, were already green.