Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

API-key authenticated GraphQL queries fail with "Invalid CSRF token" on every guarded resolver (7.4.0-beta.3)

未关闭
#2,092 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
graphql, typescript

调研方向

Start by reproducing the guarded and unguarded GraphQL requests against the /graphql endpoint with the x-api-key header, then trace the authentication and CSRF handling used by the info, array, and docker resolvers. Done means valid API-key requests reach guarded resolvers without requiring a cookie/session CSRF token, while existing session authentication remains covered.

由索引模型根据 Issue 内容生成。

描述

Environment

  • Unraid version: 7.4.0-beta.3
  • API key created via WebGUI: Settings → Management Access → API Keys, role: admin

Summary

Any GraphQL query that hits a resolver with an auth guard fails with Invalid CSRF token / UNAUTHENTICATED when authenticated purely via the x-api-key header — even though the official docs and a related report (Connect login loop from unraid-api socket path mismatch) both state that "the API responds correctly when using an explicit API key," implying API-key auth should bypass CSRF entirely (which is a cookie/session-auth concern).

This isn't intermittent — it's 100% reproducible across every guarded field I tried, while a query with no valid resolver (or a resolver with no guard, like welcome) passes authentication fine and returns a normal GraphQL error/response instead.

Steps to reproduce

# This succeeds (passes auth, hits GraphQL validation instead):
curl -s -k -X POST "https://<unraid-ip>/graphql" \
  -H "content-type: application/json" \
  -H "x-api-key: $API_KEY" \
  --data-raw '{"query":"{ welcome { message } }"}'

# This fails every time with "Invalid CSRF token":
curl -s -k -X POST "https://<unraid-ip>/graphql" \
  -H "content-type: application/json" \
  -H "x-api-key: $API_KEY" \
  --data-raw '{"query":"query { info { os { platform } } }"}'

Observed behavior

{"errors":[{"message":"Invalid CSRF token","locations":[{"line":1,"column":9}],"path":["info"],"extensions":{"code":"UNAUTHENTICATED","originalError":{"message":"Invalid CSRF token","error":"Unauthorized","statusCode":401}}}],"data":null}

Repeated 4x back-to-back with identical headers — same result every time. Also reproduced on array { state } and docker { containers { names state status } }.

Expected behavior

A request authenticated via a valid x-api-key header should authenticate the same way regardless of which resolver/field is queried — guarded resolvers shouldn't additionally require a CSRF token that only makes sense for cookie/session-based auth.

Impact

This makes the GraphQL API effectively unusable for programmatic/automation use via API keys, since essentially every field that returns real data (info, array, docker, etc.) is guarded and hits this. Only fields with no guard (e.g. welcome) work.

Possibly related to the socket-path/CSRF issue described in https://product.unraid.net/p/7-3-1-connect-login-loop-from-unraid-api-socket-path-mismatch, which may be a regression carried into this beta.

🤖 Generated with Claude Code

主要语言
TypeScript
星标
113
派生
23
平均合并
1 天 21 小时
30 天内合并 PR
12

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

unraid/api 的其他 Issue

查看 unraid/api 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。