Add session-backed CSRF token generation and verification helpers
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- sqlite
- Lĩnh vực
- backend-api-design, security
Hướng nghiên cứu
Bắt đầu bằng việc đọc các issue về dependency được liên kết #198, #203 và #199, sau đó lần theo session facility của SQLite và ví dụ về real listener của nó. Công việc được xem là hoàn tất khi các ứng dụng có thể tạo, lưu trữ, render và xác minh các synchronizer token theo định dạng cố định, phân biệt các trường hợp thất bại mà không làm rò rỉ thông tin, trích xuất một header mà không tiêu thụ body, và minh họa việc gửi một form được bảo vệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- HTML
- Star
- 110
- Fork
- 25
- Merge trung bình
- 18 giờ 28 phút
- Pull request đã merge (30 ngày)
- 16
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của roc-lang/basic-webserver
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
roc-lang/basic-webserver#277 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
roc-lang/basic-webserver#274 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
roc-lang/basic-webserver#273 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
roc-lang/basic-webserver#272 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
roc-lang/basic-webserver#265 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của roc-lang/basic-webserver
Issue tương tự
-
Fish Audio Live calls fail to start: `Unknown callback "onNotice"` from @fishaudio/agent-clientCó thể đã có người làm @NEAL3K đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
milind-soni/OpenMausBot#8345 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Feed validator crashes with "Memory error" when validating https://www.tidyverse.org/index.xmlĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
w3c/feedvalidator#204 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
open-mmlab/mmcv#3352 ·
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100