Skip to content

FT7 F-5: HTML form 用の must-call CSRF helper (requireCsrfFromPost) を追加する #316

@hideyukiMORI

Description

@hideyukiMORI

Source: FT7 (#308 / PR #311) — F-5。
Severity: high / Kind: feature-gap / Decision: fix-in-framework。

現状

`class/xion/ControllerBase.php:431-435` の `verifyCsrfFromPost(): bool` は単に bool を返す。controller 側で if 忘れがあると、bad CSRF token でも 200 + 通常 HTML が返り silent CSRF bypass になる。REST 側は `ControllerBase::run():206-208` の `requiresCsrfProtection()` が自動で 403 + JSON envelope を出すので非対称。

やること

  • 新 helper `requireCsrfFromPost(string $field = 'csrf_token'): void` を追加し、失敗時は 403 (HTML 側は `template/error/csrf.tpl` を render) で terminate
  • 既存 `verifyCsrfFromPost()` は低レベル API として残す (advanced 用途で fail recovery したい時)
  • HTML tutorial (`docs/tutorials/html-login-form.md` 等) を新 helper に書き換える
  • 既存 controller / sample で `verifyCsrfFromPost` を呼んでいる箇所を新 helper へ swap

受け入れ条件

  • 新 helper で bad token 時に response が 403 + (HTML なら) template/error/csrf.tpl になる
  • tutorial が新 helper を推奨し、bool 版は advanced ノートだけに残る
  • 既存テストが green

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions