Skip to content

feat!: enable CSRF protection for ApiFunctions by default#6496

Merged
gharlan merged 1 commit into
6.xfrom
refactor/api-function-csrf-default-true
May 9, 2026
Merged

feat!: enable CSRF protection for ApiFunctions by default#6496
gharlan merged 1 commit into
6.xfrom
refactor/api-function-csrf-default-true

Conversation

@gharlan
Copy link
Copy Markdown
Member

@gharlan gharlan commented May 9, 2026

Summary

  • Flips ApiFunction::requiresCsrfProtection() default from falsetrue and removes the now-redundant return true overrides in 22 core ApiFunctions.
  • The three endpoints that intentionally stay CSRF-free (UserSessionStatus, UserHasSession, debug API) keep their override and only get a : bool return type.
  • Resolves the long-standing BC shim noted in the docblock: "Csrf validation is disabled by default for backwards compatibility reasons. This default will change in a future version."

Breaking change

ApiFunctions in addons and projects that don't already override requiresCsrfProtection() will now require a valid CSRF token. Callers must send the token via YourApiClass::getUrlParams() / getHiddenFields(), or override the method to return false for endpoints that must remain CSRF-free (e.g. read-only or 3rd-party-callable).

🤖 Generated with Claude Code

Flips the default of `ApiFunction::requiresCsrfProtection()` from `false`
to `true` and removes the now-redundant `return true` overrides in 22
subclasses. The three endpoints that intentionally stay CSRF-free
(`UserSessionStatus`, `UserHasSession`, debug API) keep their override
and only get a `: bool` return type.

BREAKING CHANGE: ApiFunctions in addons and projects that don't already
override `requiresCsrfProtection()` will now require a valid CSRF token.
Make sure callers send the token via `YourApiClass::getUrlParams()` or
`getHiddenFields()`, or override the method to return `false` for
endpoints that must remain CSRF-free.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gharlan gharlan added this to the REDAXO 6.0 milestone May 9, 2026
@rex-bot rex-bot added breaking feature Additional functionality labels May 9, 2026
@gharlan gharlan merged commit c490c78 into 6.x May 9, 2026
16 checks passed
@gharlan gharlan deleted the refactor/api-function-csrf-default-true branch May 9, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking feature Additional functionality

Development

Successfully merging this pull request may close these issues.

2 participants