-
-
Notifications
You must be signed in to change notification settings - Fork 444
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.
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
feat: implement header param injection handling for JWT vulnerabilities #473
base: master
Are you sure you want to change the base?
Changes from 3 commits
0c23ff9
4812d61
262afac
ebcae74
be4751a
b7cea19
672b4ea
324fa33
261ea39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.sasanlabs.internal.utility.LevelConstants; | ||
|
@@ -662,4 +663,22 @@ private ResponseEntity<GenericVulnerabilityResponseBean<String>> getJWTResponseB | |
true, token, true, CollectionUtils.toMultiValueMap(headers)); | ||
return responseEntity; | ||
} | ||
|
||
@AttackVector( | ||
vulnerabilityExposed = VulnerabilityType.HEADER_INJECTION, | ||
description = "HEADER_INJECTION_VULNERABILITY_EXAMPLE") | ||
@VulnerableAppRequestMapping( | ||
value = LevelConstants.LEVEL_13, | ||
htmlTemplate = "LEVEL_13/HeaderInjection_Level13") | ||
public ResponseEntity<GenericVulnerabilityResponseBean<String>> getHeaderInjectionVulnerability( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry but there is a Level9 which has JWK based vulnerability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leiberbertel it is fine to have another vulnerability with same functionality as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, thanks for the confirmation:). |
||
HttpServletRequest request) { | ||
String headerValue = request.getHeader("User-Defined-Header"); | ||
if (headerValue != null && headerValue.contains("malicious")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @leiberbertel I think this is not the right way to implement the header param injection. The real vulnerability is with optional headers like JWK or KID or JKU as implemention of library will start relying on the data provided as part of these headers for verifying signature. Having custom/user defined headers is not wrong or considered malicious. A simple attack is say JWT library is relying on the public key provided as part of JWK header instead of validating the public key provided with the whitelisted public key set. so attack would be a malicious user will generate key pairs and sign the jwt with its own private key and passed public key as JWK header. The backend will not validate public key against a whitelist and start relying on provided public key to validate the JWT. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @preetkaran20, My intent with the current implementation was to demonstrate how user-defined headers can be manipulated, but I see that focusing on these critical headers such as JWK could provide a more realistic and educational example of common vulnerabilities in JWTs. I will revise the implementation to incorporate these examples, ensuring that we clearly demonstrate how the lack of proper validation of public keys can be exploited. Regards. |
||
return new ResponseEntity<>( | ||
new GenericVulnerabilityResponseBean<>("Vulnerability exploited!", false), | ||
HttpStatus.OK); | ||
} | ||
return new ResponseEntity<>( | ||
new GenericVulnerabilityResponseBean<>("Safe header", true), HttpStatus.OK); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#header_injection_level_13 { | ||
color: black; | ||
text-align: justify; | ||
} | ||
|
||
#enterHeader { | ||
font-size: 15px; | ||
display: flex; | ||
margin: 10px; | ||
flex-direction: column; | ||
} | ||
|
||
#headerName, #headerValue { | ||
flex: 1; | ||
word-wrap: break-word; | ||
margin-top: 10px; | ||
} | ||
|
||
#headerResponse { | ||
font-size: 15px; | ||
word-wrap: break-word; | ||
text-align: center; | ||
margin: 10px; | ||
} | ||
|
||
#sendHeader { | ||
background: blueviolet; | ||
display: inline-block; | ||
padding: 4px 4px; | ||
margin: 10px; | ||
border: 1px solid transparent; | ||
border-radius: 2px; | ||
transition: 0.2s opacity; | ||
color: #FFF; | ||
font-size: 12px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Header Injection</title> | ||
</head> | ||
<body> | ||
<div id="header_injection_level_13"> | ||
<div> | ||
<div id="enterHeader"> | ||
<div>Header Name:</div> | ||
<input type="text" id="headerName" placeholder="Enter header name" /> | ||
<div>Header Value:</div> | ||
<input type="text" id="headerValue" placeholder="Enter header value" /> | ||
</div> | ||
<button id="sendHeader">Send Header</button> | ||
<div id="headerResponse"></div> | ||
</div> | ||
</div> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function addEventListenerToSendHeaderButton() { | ||
document.getElementById("sendHeader").addEventListener("click", function () { | ||
const headerName = document.getElementById("headerName").value; | ||
const headerValue = document.getElementById("headerValue").value; | ||
|
||
let url = getUrlForVulnerabilityLevel(); | ||
|
||
doGetAjaxCall( | ||
function (data) { | ||
document.getElementById("headerResponse").innerHTML = data.isValid | ||
? "Header Injection was successful!" | ||
: "Header Injection failed. Please try again."; | ||
}, | ||
url, | ||
true, | ||
{ | ||
[headerName]: headerValue, | ||
} | ||
); | ||
}); | ||
} | ||
|
||
addEventListenerToSendHeaderButton(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,7 +235,7 @@ function genericResponseHandler(xmlHttpRequest, callBack, isJson) { | |
} | ||
} | ||
|
||
function doGetAjaxCall(callBack, url, isJson) { | ||
function doGetAjaxCall(callBack, url, isJson, headers = {}) { | ||
let xmlHttpRequest = new XMLHttpRequest(); | ||
xmlHttpRequest.onreadystatechange = function () { | ||
genericResponseHandler(xmlHttpRequest, callBack, isJson); | ||
|
@@ -245,6 +245,11 @@ function doGetAjaxCall(callBack, url, isJson) { | |
"Content-Type", | ||
isJson ? "application/json" : "text/html" | ||
); | ||
|
||
for (const header in headers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this change. |
||
xmlHttpRequest.setRequestHeader(header, headers[header]); | ||
} | ||
|
||
xmlHttpRequest.send(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the Locale Key for description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have updated it