Skip to content

docs: correct CSRF protection opt-in description - #30

Merged
koriym merged 6 commits into
1.xfrom
claude/review-csrf-protection-yjrZA
May 20, 2026
Merged

koriym merged 6 commits into
1.xfrom
claude/review-csrf-protection-yjrZA

Conversation

@koriym

@koriym koriym commented May 19, 2026 •

Copy link
Copy Markdown
Member

Summary

The README sections on CSRF protection claimed that SetAntiCsrfTrait only wires AntiCsrfInterface into the form and that token verification requires #[CsrfProtection]:

A form that uses SetAntiCsrfTrait is wired with an AntiCsrfInterface, but the token is only verified when the validated method is annotated with #[CsrfProtection]. Methods without #[CsrfProtection] perform no CSRF check even if the form supports it.

This is not what the code does.

SetAntiCsrfTrait::setAntiCsrf() is annotated with #[Inject], so DI populates $this->antiCsrf at construction. AbstractForm::postConstruct() then calls enableAntiCsrf() to add the token field, and AbstractForm::apply() throws CsrfViolationException on token mismatch — regardless of whether the controller method has #[CsrfProtection]. This is exercised by AbstractFormTest::testAntiCsrfViolation, which sets antiCsrf directly on the form (no interceptor, no attribute) and asserts the throw.

So there are two independent opt-in paths and the README/skill should describe them as such.

Changes

  • README.md / README.JA.md: rewrite the "CSRF Protections" intro to describe the two independent paths (per-form trait vs. per-action attribute) and state that either causes apply() to throw on mismatch.
  • .claude/skills/migrate-to-1.0/SKILL.md: replace the "out of scope" bullet that said forms using SetAntiCsrfTrait without #[CsrfProtection] "will silently stop enforcing CSRF in 1.0" — the actual at-risk case is the removed @FormValidation(antiCsrf=true) option when the form did not also use the trait.

Test plan

  • Manual reading: README example (use SetAntiCsrfTrait; + no #[CsrfProtection] on controller) is consistent with AbstractFormTest::testAntiCsrfViolation.
  • No code changes; existing tests still pass.

Generated by Claude Code

Summary by CodeRabbit

  • Documentation
    • Clarified CSRF protection is opt-in with two independent activation paths: per-form (SetAntiCsrfTrait) and per-action (#[CsrfProtection])
    • Reorganized examples into separate per-action and per-form guides; noted enabling both is harmless but redundant
    • Specified exception behavior on token mismatch and updated migration guidance after removal of the prior antiCsrf option, including note on redundant inserted attributes
    • Updated Japanese README accordingly
  • Chores
    • Lint config updated to require fenced code blocks

Review Change Stack

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants