Add session-backed CSRF token generation and verification helpers
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- sqlite
調査の方向性
まず、リンクされている依存関係の issue #198、#203、#199 を読み、続いて SQLite のセッション機能と、その実際の listener を使った例を追ってください。完了条件は、アプリケーションが固定形式の synchronizer token を生成、保存、レンダリング、検証でき、リークなしに失敗ケースを区別でき、body を消費せずに header を抽出でき、保護されたフォーム送信を実証できることです。
索引モデルが issue の本文から書いたものです。
説明
Summary
Add a focused Csrf module implementing the synchronizer-token building blocks needed by HTML forms and browser APIs.
Illustrative API:
token = Csrf.generate!() # persist in the server-side session
form_value = token.to_str()
match Csrf.verify({
expected: Csrf.from_stored(session.csrf_token)?,
presented: submitted_value,
}) {
Valid => handle_state_change()
Invalid(reason) => forbidden(reason)
}
Dependencies
- #198 for OS-backed cryptographic random bytes
- #203 for the intended server-side session integration
- #199 for the surrounding session-cookie flow
Why this should not be generic middleware
CSRF enforcement depends on route semantics, authentication, and where the application obtains the submitted token. A form handler may need to parse a bounded URL-encoded or multipart body before verification, while a JSON endpoint normally reads a header.
Automatically consuming request bodies or guessing which methods and routes are safe would conflict with the explicit request-body and routing model. The platform should instead provide a difficult-to-misuse token type and verification function.
OWASP recommends server-generated, secret, unpredictable synchronizer tokens that are compared with session state. It also warns against placing synchronizer tokens in cookies, URLs, or logs.
Required contract
- Generate tokens from at least 32 bytes returned by
Random.bytes!. - Use a fixed cookie/form-safe representation with strict parsing.
- Make the token nominal and redact its normal inspection.
- Verify token values with a constant-time comparison after validating their fixed length and encoding.
- Distinguish missing, malformed, and mismatched tokens.
- Provide a helper for extracting exactly one configured request header without consuming the body.
- Form handlers parse their own bounded body and pass the presented value explicitly.
- Document that the application stores the expected token in its server-side session.
- Rotate the token on session creation, authentication, and session-identifier rotation.
- Never emit token values in error messages, access logs, or metrics.
- Provide an end-to-end form example using the SQLite session facility.
Non-goals
- Automatic protection of all
POSTrequests - Guessing safe routes or methods
- Consuming form or multipart bodies behind the application
- CORS policy
- A naive double-submit cookie design
- Stateless signed tokens or general HMAC APIs
- Origin/Referer validation based on untrusted forwarded headers
Acceptance criteria
- Applications can generate, persist, render, and verify synchronizer tokens.
- Verification uses fixed-format parsing and constant-time comparison.
- Missing, malformed, and mismatched values are distinguishable without leaking secrets.
- Header extraction never consumes the request body.
- A real-listener example demonstrates session cookie plus protected form submission.
References
- 主要言語
- HTML
- スター
- 110
- フォーク
- 25
- 平均マージ
- 18時間 28分
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
roc-lang/basic-webserver のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
roc-lang/basic-webserver#277 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
roc-lang/basic-webserver#274 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
roc-lang/basic-webserver#273 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
roc-lang/basic-webserver#272 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
roc-lang/basic-webserver#265 ·
メンテナーはふだん 1 日以内に返信
roc-lang/basic-webserver の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OHDSI/Data2Evidence#3815 ·
メンテナーはふだん 3 日以内に返信
-
e2e-failure ready-to-code
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
redhat-developer/rhdh-plugin-export-overlays#4995 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
fidelity
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hosts対応中かも @huanghaoyuanhhy が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
zilliztech/milvus-backup#1418 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] download repeatedly fetches unchanged gzip responses due to compressed/decoded size mismatch対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
stanfordnlp/dspy#11000 ·
メンテナーはふだん 1 日以内に返信