Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatting
  • Loading branch information
Kwstubbs committed Oct 18, 2023
commit fa15d2954779c6aee0731d5cc3135496cf0dbf7e
21 changes: 12 additions & 9 deletions go/ql/src/experimental/CWE-347/JWTParsingAlgorithm.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
* external/cwe/cwe-347
*/

import go
import experimental.frameworks.JWT
import DataFlow


import go
import experimental.frameworks.JWT
import DataFlow

/**
* A parse function that verifies signature and accepts all methods.
*/
class SafeJwtParserFunc extends Function {
SafeJwtParserFunc() {
this.hasQualifiedName(golangJwtPackage(), ["Parse", "ParseWithClaims"])
}
SafeJwtParserFunc() { this.hasQualifiedName(golangJwtPackage(), ["Parse", "ParseWithClaims"]) }
}

/**
* A parse method that verifies signature.
*/
class SafeJwtParserMethod extends Method {
SafeJwtParserMethod() {
this.hasQualifiedName(golangJwtPackage(), "Parser", ["Parse", "ParseWithClaims"])
Expand Down Expand Up @@ -51,4 +54,4 @@ where
f.getARead().getRoot() = c.getCall().getAnArgument()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to specify which argument?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think this only works if the function literal is specified in place. If it's assigned to a variable and then that variable is used as an argument, would this catch it?

Copy link
Copy Markdown
Contributor Author

@Kwstubbs Kwstubbs Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owen-mc having a bit of trouble coming up with a good way to see if the function name that is passed into the argument has a field read of the Method or not. If you can find another way that avoids strings altogether please let me know.

)
)
select c, "This Parse Call to Verify the JWT token may be vulnerable to algorithim confusion"
select c, "This Parse Call to Verify the JWT token may be vulnerable to algorithim confusion"
6 changes: 3 additions & 3 deletions go/ql/src/experimental/frameworks/JWT.qll
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ class GoJoseUnsafeClaims extends JwtUnverifiedParse {
override int getTokenArgNum() { result = -1 }
}

/**
* A function in golang-jwt to specify allowed algorithms.
*/
/**
* A function in golang-jwt to specify allowed algorithms.
*/
class WithValidMethods extends Function {
WithValidMethods() { this.hasQualifiedName(golangJwtRequestPackage(), "WithValidMethods") }
}
Expand Down