File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
java/ql/src/Security/CWE/CWE-798 Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ // BAD: Get secret from hardcoded string then sign a JWT token
2+ Algorithm algorithm = Algorithm .HMAC256 ("hardcoded_secret" );
3+ JWT .create ()
4+ .withClaim ("username" , username )
5+ .sign (algorithm );
6+ }
7+
8+ // BAD: Get secret from hardcoded string then verify a JWT token
9+ JWTVerifier verifier = JWT .require (Algorithm .HMAC256 ("hardcoded_secret" ))
10+ .withIssuer (ISSUER )
11+ .build ();
12+ verifier .verify (token );
13+
14+ // GOOD: Get secret from system configuration then sign a token
15+ String tokenSecret = System .getenv ("SECRET_KEY" );
16+ Algorithm algorithm = Algorithm .HMAC256 (tokenSecret );
17+ JWT .create ()
18+ .withClaim ("username" , username )
19+ .sign (algorithm );
20+ }
21+
22+ // GOOD: Get secret from environment variable then verify a JWT token
23+ JWTVerifier verifier = JWT .require (Algorithm .HMAC256 (System .getenv ("SECRET_KEY" )))
24+ .withIssuer (ISSUER )
25+ .build ();
26+ verifier .verify (token );
You can’t perform that action at this time.
0 commit comments