File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
java/ql/test/query-tests/security/CWE-798/semmle/tests Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -62,4 +62,49 @@ public boolean verifyTokenGood(String token) {
6262 return false ;
6363 }
6464 }
65+
66+ public String accessTokenBad384 (String username ) {
67+ Algorithm algorithm = Algorithm .HMAC384 (SECRET ); // $ HardcodedCredentialsApiCall
68+
69+ return JWT .create ()
70+ .withExpiresAt (new Date (new Date ().getTime () + ACCESS_EXPIRE_TIME ))
71+ .withIssuer (ISSUER )
72+ .withClaim ("username" , username )
73+ .sign (algorithm );
74+ }
75+
76+ // GOOD: Get secret from system configuration then sign a token
77+ public String accessTokenGood384 (String username ) {
78+ String tokenSecret = System .getenv ("SECRET_KEY" );
79+ Algorithm algorithm = Algorithm .HMAC384 (tokenSecret );
80+
81+ return JWT .create ()
82+ .withExpiresAt (new Date (new Date ().getTime () + ACCESS_EXPIRE_TIME ))
83+ .withIssuer (ISSUER )
84+ .withClaim ("username" , username )
85+ .sign (algorithm );
86+ }
87+
88+ public String accessTokenBad512 (String username ) {
89+ Algorithm algorithm = Algorithm .HMAC512 (SECRET ); // $ HardcodedCredentialsApiCall
90+
91+ return JWT .create ()
92+ .withExpiresAt (new Date (new Date ().getTime () + ACCESS_EXPIRE_TIME ))
93+ .withIssuer (ISSUER )
94+ .withClaim ("username" , username )
95+ .sign (algorithm );
96+ }
97+
98+ // GOOD: Get secret from system configuration then sign a token
99+ public String accessTokenGood512 (String username ) {
100+ String tokenSecret = System .getenv ("SECRET_KEY" );
101+ Algorithm algorithm = Algorithm .HMAC512 (tokenSecret );
102+
103+ return JWT .create ()
104+ .withExpiresAt (new Date (new Date ().getTime () + ACCESS_EXPIRE_TIME ))
105+ .withIssuer (ISSUER )
106+ .withClaim ("username" , username )
107+ .sign (algorithm );
108+ }
109+
65110}
You can’t perform that action at this time.
0 commit comments