Repository navigation
Conversation
新增 `uvcpp_web_auth`(`src/webapp/uvcpp_web_auth.*`): - **RBAC**:角色存会话(默认键 `roles`,逗号分隔);`uvcpp_session_set_roles()` / `uvcpp_session_has_role()` / `uvcpp_require_roles(list)`(任一命中,OR); 无会话或会话里没有角色键 → 401,有角色但不匹配 → 403;`skip_paths` 精确匹配放行(登录/健康检查)。 - **CSRF(双提交 + 会话绑定)**:每会话随机 token,存会话 + 发**非 HttpOnly** Cookie(SameSite=Strict 可配);不安全方法(非 GET/HEAD/OPTIONS)要求 `X-CSRF-Token` 头或表单 `_csrf` 与会话 token 逐字节相同,否则 403; token 比较走常数时间循环;没装会话中间件时返回 500(配置错误不静默放行)。 用例 `web_app_auth_func`:无角色 401、admin 登录后放行、要求 user 时 403、 缺/错 CSRF 403、头部与表单两条路径通过、CSRF Cookie 非 HttpOnly 且 SameSite=Strict。文档 `doc/webapp-guide.md` §23。 本地 build-all 171/171、build-h3/default 编过;五条文档门禁全绿。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #70(第二批:RBAC + CSRF;密码哈希、登录限流、审计留后续)。
内容
新增
uvcpp_web_auth:RBAC
roles,逗号分隔);uvcpp_session_set_roles()/uvcpp_session_has_role()/uvcpp_require_roles(list);require_roles是任一命中(OR);skip_paths按归一化路径精确匹配放行(登录、健康检查)。CSRF(双提交 + 会话绑定)
SameSite默认Strict;X-CSRF-Token头或表单_csrf,与会话 token 逐字节相同(常数时间比较),否则 403;csrf_protect()返回 500(配置错误不静默放行);用例
web_app_auth_func:/admin→ 401;POST /login缺 CSRF → 403,带X-CSRF-Token→ 200 并写入 admin 角色,随后/admin→ 200;user角色的队列里只有 admin → 403;_csrf=路径同样通过;POST /admin缺 token → 403、带 token → 200;SameSite=Strict。验证
build-all 171/171、build-h3 / build-default 编过;check_docs / check_doc_lines / check_doc_versions / check_ci_layout 全绿。文档
doc/webapp-guide.md§23。