-
Notifications
You must be signed in to change notification settings - Fork 306
Store the http.route tag value inside the iast request context in Play #9105
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
Merged
jandro996
merged 15 commits into
master
from
alejandro.gonzalez/add-http-route-play-in-iast
Jul 10, 2025
+1,093
−23
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0275a50
WIP
jandro996 0259391
WIP
jandro996 2a56b37
WIP
jandro996 22fbd3f
WIP
jandro996 2dbdc62
Merge branch 'master' into alejandro.gonzalez/add-http-route-play-in-…
jandro996 418be3b
WIP
jandro996 58a6f39
change approach to on request enter
jandro996 411682f
try simple approach moving dispatchRoute to on request enter
jandro996 ecab2f5
Update dd-smoke-tests/iast-util/src/testFixtures/groovy/datadog/smoke…
jandro996 a7c0869
Merge branch 'master' into alejandro.gonzalez/add-http-route-play-in-…
jandro996 664ea78
fix codenarc
jandro996 39bf456
remove dependency
jandro996 ca3b9ed
Merge branch 'master' into alejandro.gonzalez/add-http-route-play-in-…
jandro996 ff31a0f
Add comments
jandro996 fde0164
Merge branch 'master' into alejandro.gonzalez/add-http-route-play-in-…
jandro996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
dd-java-agent/agent-iast/src/main/java/com/datadog/iast/HttpRouteHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.datadog.iast; | ||
|
||
import datadog.trace.api.gateway.RequestContext; | ||
import datadog.trace.api.gateway.RequestContextSlot; | ||
import java.util.function.BiConsumer; | ||
|
||
public class HttpRouteHandler implements BiConsumer<RequestContext, String> { | ||
|
||
@Override | ||
public void accept(final RequestContext ctx, final String route) { | ||
final IastRequestContext iastCtx = ctx.getData(RequestContextSlot.IAST); | ||
if (iastCtx != null) { | ||
iastCtx.setRoute(route); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/HttpRouteHandlerTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.datadog.iast | ||
|
||
import datadog.trace.api.gateway.RequestContext | ||
import datadog.trace.api.gateway.RequestContextSlot | ||
import datadog.trace.test.util.DDSpecification | ||
import groovy.transform.CompileDynamic | ||
|
||
@CompileDynamic | ||
class HttpRouteHandlerTest extends DDSpecification { | ||
void 'route is set'() { | ||
given: | ||
final handler = new HttpRouteHandler() | ||
final iastCtx = Mock(IastRequestContext) | ||
final ctx = Mock(RequestContext) | ||
ctx.getData(RequestContextSlot.IAST) >> iastCtx | ||
|
||
when: | ||
handler.accept(ctx, '/foo') | ||
|
||
then: | ||
1 * ctx.getData(RequestContextSlot.IAST) >> iastCtx | ||
1 * iastCtx.setRoute('/foo') | ||
0 * _ | ||
} | ||
|
||
void 'does nothing when context missing'() { | ||
given: | ||
final handler = new HttpRouteHandler() | ||
final ctx = Mock(RequestContext) | ||
ctx.getData(RequestContextSlot.IAST) >> null | ||
|
||
when: | ||
handler.accept(ctx, '/foo') | ||
|
||
then: | ||
1 * ctx.getData(RequestContextSlot.IAST) >> null | ||
0 * _ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
dd-smoke-tests/play-2.4/app/controllers/IastController.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controllers | ||
|
||
import play.api.mvc._ | ||
|
||
import java.nio.charset.StandardCharsets | ||
import java.security.MessageDigest | ||
|
||
class IastController extends Controller { | ||
|
||
def multipleVulns(id: String): Action[AnyContent] = Action { | ||
try { | ||
MessageDigest.getInstance("SHA1").digest("hash1".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("SHA-1").digest("hash2".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("MD2").digest("hash3".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("MD5").digest("hash4".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("RIPEMD128").digest("hash5".getBytes(StandardCharsets.UTF_8)) | ||
Ok("ok") | ||
} catch { | ||
case e: Exception => InternalServerError(e.getMessage) | ||
} | ||
} | ||
|
||
def postMultipleVulns(id: String): Action[AnyContent] = Action { | ||
try { | ||
MessageDigest.getInstance("SHA1").digest("hash1".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("SHA-1").digest("hash2".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("MD2").digest("hash3".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("MD5").digest("hash4".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("RIPEMD128").digest("hash5".getBytes(StandardCharsets.UTF_8)) | ||
Ok("ok") | ||
} catch { | ||
case e: Exception => InternalServerError(e.getMessage) | ||
} | ||
} | ||
|
||
def multipleVulns2(id: String): Action[AnyContent] = Action { | ||
try { | ||
MessageDigest.getInstance("SHA1").digest("hash1".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("SHA-1").digest("hash2".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("MD2").digest("hash3".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("MD5").digest("hash4".getBytes(StandardCharsets.UTF_8)) | ||
MessageDigest.getInstance("RIPEMD128").digest("hash5".getBytes(StandardCharsets.UTF_8)) | ||
Ok("ok") | ||
} catch { | ||
case e: Exception => InternalServerError(e.getMessage) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
I will leave a comment here that's it has been moved to onEntry in case we have issues in future because of this.