GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java: Promote Hardcoded JWT credential query by egregius313 · Pull Request #12032 · github/codeql

Java: Promote Hardcoded JWT credential query #12032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
egregius313 merged 7 commits into github:main from egregius313:egregius313/promote-hardcoded-jwt-credential
Feb 27, 2023

Uh oh!

There was an error while loading. Please reload this page.

Merged

Java: Promote Hardcoded JWT credential query #12032

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7 commits
Select commit Hold shift + click to select a range
fa6ac06
Add com.auth0.jwt.algorithm.Algorithm sinks
egregius313 Jan 30, 2023
d71386e
Add example file for documentation
egregius313 Jan 30, 2023
3ff1a97
Add `byte[]` signatures
egregius313 Feb 14, 2023
6de946e
Remove experimental files
egregius313 Feb 17, 2023
4aec708
Add change note
egregius313 Feb 17, 2023
06a1368
Additional test cases
egregius313 Feb 17, 2023
ed1aac1
Remove unneeded example file
egregius313 Feb 21, 2023
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 4 additions & 0 deletions 4 java/ql/lib/change-notes/2023-02-17-add-hardcoded-secret-for-jwt-tokens.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Added new sinks for `java/hardcoded-credential-api-call` to identify the use of hardcoded secrets in the creation and verification of JWT tokens using `com.auth0.jwt`. These sinks are from [an experimental query submitted by @luchua](https://github.com/github/codeql/pull/9036).
6 changes: 6 additions & 0 deletions 6 java/ql/lib/semmle/code/java/security/SensitiveApi.qll
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,11 @@ private predicate otherApiCallableCredentialParam(string s) {
"com.microsoft.sqlserver.jdbc.SQLServerDataSource;setPassword(String);0",
"com.microsoft.sqlserver.jdbc.SQLServerDataSource;getConnection(String, String);0",
"com.microsoft.sqlserver.jdbc.SQLServerDataSource;getConnection(String, String);1",
"com.auth0.jwt.algorithms.Algorithm;HMAC256(String);0",
"com.auth0.jwt.algorithms.Algorithm;HMAC256(byte[]);0",
"com.auth0.jwt.algorithms.Algorithm;HMAC384(String);0",
"com.auth0.jwt.algorithms.Algorithm;HMAC384(byte[]);0",
"com.auth0.jwt.algorithms.Algorithm;HMAC512(String);0",
"com.auth0.jwt.algorithms.Algorithm;HMAC512(byte[]);0"
]
}
26 changes: 0 additions & 26 deletions 26 java/ql/src/experimental/Security/CWE/CWE-321/HardcodedJwtKey.java
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

46 changes: 0 additions & 46 deletions 46 java/ql/src/experimental/Security/CWE/CWE-321/HardcodedJwtKey.qhelp
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

20 changes: 0 additions & 20 deletions 20 java/ql/src/experimental/Security/CWE/CWE-321/HardcodedJwtKey.ql
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

131 changes: 0 additions & 131 deletions 131 java/ql/src/experimental/Security/CWE/CWE-321/HardcodedJwtKey.qll
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

25 changes: 0 additions & 25 deletions 25 java/ql/test/experimental/query-tests/security/CWE-321/HardcodedJwtKey.expected
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 change: 0 additions & 1 deletion 1 java/ql/test/experimental/query-tests/security/CWE-321/HardcodedJwtKey.qlref
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 change: 0 additions & 1 deletion 1 java/ql/test/experimental/query-tests/security/CWE-321/options
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

49 changes: 47 additions & 2 deletions 49 ...sts/security/CWE-321/HardcodedJwtKey.java → ...CWE-798/semmle/tests/HardcodedJwtKey.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HardcodedJwtKey {

// BAD: Get secret from hardcoded string then sign a JWT token
public String accessTokenBad(String username) {
Algorithm algorithm = Algorithm.HMAC256(SECRET);
Algorithm algorithm = Algorithm.HMAC256(SECRET); // $ HardcodedCredentialsApiCall

return JWT.create()
.withExpiresAt(new Date(new Date().getTime() + ACCESS_EXPIRE_TIME))
Expand All @@ -39,7 +39,7 @@ public String accessTokenGood(String username) {

// BAD: Get secret from hardcoded string then verify a JWT token
public boolean verifyTokenBad(String token) {
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(SECRET))
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(SECRET)) // $ HardcodedCredentialsApiCall
.withIssuer(ISSUER)
.build();
try {
Expand All @@ -62,4 +62,49 @@ public boolean verifyTokenGood(String token) {
return false;
}
}

public String accessTokenBad384(String username) {
Algorithm algorithm = Algorithm.HMAC384(SECRET); // $ HardcodedCredentialsApiCall

return JWT.create()
.withExpiresAt(new Date(new Date().getTime() + ACCESS_EXPIRE_TIME))
.withIssuer(ISSUER)
.withClaim("username", username)
.sign(algorithm);
}

// GOOD: Get secret from system configuration then sign a token
public String accessTokenGood384(String username) {
String tokenSecret = System.getenv("SECRET_KEY");
Algorithm algorithm = Algorithm.HMAC384(tokenSecret);

return JWT.create()
.withExpiresAt(new Date(new Date().getTime() + ACCESS_EXPIRE_TIME))
.withIssuer(ISSUER)
.withClaim("username", username)
.sign(algorithm);
}

public String accessTokenBad512(String username) {
Algorithm algorithm = Algorithm.HMAC512(SECRET); // $ HardcodedCredentialsApiCall

return JWT.create()
.withExpiresAt(new Date(new Date().getTime() + ACCESS_EXPIRE_TIME))
.withIssuer(ISSUER)
.withClaim("username", username)
.sign(algorithm);
}

// GOOD: Get secret from system configuration then sign a token
public String accessTokenGood512(String username) {
String tokenSecret = System.getenv("SECRET_KEY");
Algorithm algorithm = Algorithm.HMAC512(tokenSecret);

return JWT.create()
.withExpiresAt(new Date(new Date().getTime() + ACCESS_EXPIRE_TIME))
.withIssuer(ISSUER)
.withClaim("username", username)
.sign(algorithm);
}

}
2 changes: 1 addition & 1 deletion 2 java/ql/test/query-tests/security/CWE-798/semmle/tests/options
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/amazon-aws-sdk-1.11.700:${testdir}/../../../../../stubs/azure-sdk-for-java:${testdir}/../../../../../stubs/shiro-core-1.4.0:${testdir}/../../../../../stubs/jsch-0.1.55:${testdir}/../../../../../stubs/ganymed-ssh-2-260:${testdir}/../../../../../stubs/apache-mina-sshd-2.8.0:${testdir}/../../../../../stubs/sshj-0.33.0:${testdir}/../../../../../stubs/j2ssh-1.5.5:${testdir}/../../../../../stubs/trilead-ssh2-212:${testdir}/../../../../../stubs/apache-commons-net-3.8.0:${testdir}/../../../../../stubs/mongodbClient:${testdir}/../../../../../stubs/mssql-jdbc-12.2.0
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/amazon-aws-sdk-1.11.700:${testdir}/../../../../../stubs/azure-sdk-for-java:${testdir}/../../../../../stubs/shiro-core-1.4.0:${testdir}/../../../../../stubs/jsch-0.1.55:${testdir}/../../../../../stubs/ganymed-ssh-2-260:${testdir}/../../../../../stubs/apache-mina-sshd-2.8.0:${testdir}/../../../../../stubs/sshj-0.33.0:${testdir}/../../../../../stubs/j2ssh-1.5.5:${testdir}/../../../../../stubs/trilead-ssh2-212:${testdir}/../../../../../stubs/apache-commons-net-3.8.0:${testdir}/../../../../../stubs/mongodbClient:${testdir}/../../../../../stubs/mssql-jdbc-12.2.0:${testdir}/../../../../../stubs/auth0-jwt-2.3
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.