fix(django): let django-no-csrf-token span realistic form bodies - #4025
fix(django): let django-no-csrf-token span realistic form bodies#4025Eljees wants to merge 2 commits into
Conversation
In generic mode an ellipsis matches at most 10 newlines by default,
which is smaller than a real form body. Two things follow from that:
the csrf_token exemption stops matching once the body grows, so a form
that does contain {% csrf_token %} is reported, and a longer form is not
matched at all, so a form that is genuinely missing the token is
silently skipped.
Raise generic_ellipsis_max_span for this rule so both the exemption and
the rule itself reach through a normal form.
Signed-off-by: Eljees <3.14hell@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba0345790e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thanks — I checked the cross-form concern before changing anything, and I can't reproduce it. The Three layouts, all with the patched rule (
So raising the span doesn't let the exemption leak across form boundaries. Happy to add one of these as a regression test in this PR if you'd like it pinned down. |
Signed-off-by: Eljees <3.14hell@gmail.com>
|
Ping — open since 28 July, no review yet. Checks are green on In generic mode an ellipsis spans at most 10 newlines, so a 13-line form that does contain I also checked the obvious risk — that raising the span lets the exemption leak from one form into a neighbouring one. Three layouts are in the thread; the unprotected form is still reported in all three. Happy to adjust the span or the approach. |
Fixes #3816
Problem
In generic mode an ellipsis matches at most 10 newlines (
generic_ellipsis_max_span, default 10). A real form body is longer than that, which breaks the rule in two directions.Measured on the reporter's templates plus two variants, with the rule as it is on
developversus with the option raised:{% csrf_token %}(nested{% if %}, multi-line element){% csrf_token %}(same, collapsed to one line)So the same limit that hides the
{% csrf_token %}exemption on a slightly larger form also stops the rule from matching longer forms at all. The false negative is the more dangerous half, and it is invisible to users.Change
One
options:block on the rule raisinggeneric_ellipsis_max_spanto 50, so both the main pattern and thepattern-not-insideexemptions reach through a normal form body.50 is a judgement call — large enough for realistic templates, still bounded. Happy to move it if you'd prefer a different ceiling.
Tests
django-no-csrf-token.htmlgains the reporter's template as anokcase and a longer token-less form as aruleidcase (the latter fails without this change).