Fix NullPointerException in unvalidated redirect detection (#5755)#5759
Merged
Conversation
Under some circumstances, the `name` field of an IAST source can be `null` (very rare, and generally an indicative of another issue, but it's currently legal). In this case, the unvalidated redirect detection can throw a NPE. This NPE is caught in the instrumentation, so it will not break the app, but it will log to debug: ``` [dd.trace 2023-08-22 18:49:20:322 +0200] [http-nio-20002-exec-3] DEBUG datadog.trace.bootstrap.ExceptionLogger - Failed to handle exception in instrumentation for org.springframework.web.method.support.InvocableHandlerMethod java.lang.NullPointerException at com.datadog.iast.sink.UnvalidatedRedirectModuleImpl.isRefererHeader(UnvalidatedRedirectModuleImpl.java:102) at com.datadog.iast.sink.UnvalidatedRedirectModuleImpl.checkUnvalidatedRedirect(UnvalidatedRedirectModuleImpl.java:74) at com.datadog.iast.sink.UnvalidatedRedirectModuleImpl.onRedirect(UnvalidatedRedirectModuleImpl.java:41) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1070) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) ```
manuel-alvarez-alvarez
approved these changes
Aug 23, 2023
BenchmarksStartupParameters
See matching parameters
SummaryFound 8 performance improvements and 2 performance regressions! Performance is the same for 52 cases.
Startup time reports for insecure-bankgantt
title insecure-bank - global startup overhead: candidate=1.20.0-SNAPSHOT~1d67af6510, baseline=1.20.0-SNAPSHOT~cbe55c2700
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (987.473 ms) : 0, 987473
Total [baseline] (8.666 s) : 0, 8665713
Agent [candidate] (982.543 ms) : 0, 982543
Total [candidate] (8.642 s) : 0, 8641762
section appsec
Agent [baseline] (1.073 s) : 0, 1072551
Total [baseline] (8.718 s) : 0, 8717682
Agent [candidate] (1.076 s) : 0, 1076095
Total [candidate] (8.726 s) : 0, 8725810
section iast
Agent [baseline] (1.088 s) : 0, 1087785
Total [baseline] (9.201 s) : 0, 9200803
Agent [candidate] (1.081 s) : 0, 1081498
Total [candidate] (9.206 s) : 0, 9205582
section profiling
Agent [baseline] (1.159 s) : 0, 1158584
Total [baseline] (8.895 s) : 0, 8895310
Agent [candidate] (1.153 s) : 0, 1153414
Total [candidate] (8.876 s) : 0, 8875613
gantt
title insecure-bank - break down per module: candidate=1.20.0-SNAPSHOT~1d67af6510, baseline=1.20.0-SNAPSHOT~cbe55c2700
dateFormat X
axisFormat %s
section tracing
BytebuddyAgent [baseline] (612.026 ms) : 0, 612026
BytebuddyAgent [candidate] (608.014 ms) : 0, 608014
GlobalTracer [baseline] (284.041 ms) : 0, 284041
GlobalTracer [candidate] (283.62 ms) : 0, 283620
AppSec [baseline] (50.387 ms) : 0, 50387
AppSec [candidate] (50.674 ms) : 0, 50674
Remote Config [baseline] (666.086 µs) : 0, 666
Remote Config [candidate] (667.953 µs) : 0, 668
Telemetry [baseline] (6.002 ms) : 0, 6002
Telemetry [candidate] (5.42 ms) : 0, 5420
section appsec
BytebuddyAgent [baseline] (611.892 ms) : 0, 611892
BytebuddyAgent [candidate] (613.587 ms) : 0, 613587
GlobalTracer [baseline] (284.448 ms) : 0, 284448
GlobalTracer [candidate] (286.283 ms) : 0, 286283
AppSec [baseline] (135.39 ms) : 0, 135390
AppSec [candidate] (135.86 ms) : 0, 135860
Remote Config [baseline] (728.555 µs) : 0, 729
Remote Config [candidate] (721.15 µs) : 0, 721
Telemetry [baseline] (5.777 ms) : 0, 5777
Telemetry [candidate] (5.171 ms) : 0, 5171
section iast
BytebuddyAgent [baseline] (716.581 ms) : 0, 716581
BytebuddyAgent [candidate] (710.16 ms) : 0, 710160
GlobalTracer [baseline] (269.761 ms) : 0, 269761
GlobalTracer [candidate] (270.692 ms) : 0, 270692
AppSec [baseline] (47.163 ms) : 0, 47163
AppSec [candidate] (47.04 ms) : 0, 47040
Remote Config [baseline] (546.276 µs) : 0, 546
Remote Config [candidate] (635.428 µs) : 0, 635
Telemetry [baseline] (5.671 ms) : 0, 5671
Telemetry [candidate] (5.562 ms) : 0, 5562
IAST [baseline] (13.764 ms) : 0, 13764
IAST [candidate] (13.208 ms) : 0, 13208
section profiling
BytebuddyAgent [baseline] (627.035 ms) : 0, 627035
BytebuddyAgent [candidate] (622.95 ms) : 0, 622950
GlobalTracer [baseline] (346.656 ms) : 0, 346656
GlobalTracer [candidate] (346.918 ms) : 0, 346918
AppSec [baseline] (49.118 ms) : 0, 49118
AppSec [candidate] (49.18 ms) : 0, 49180
Remote Config [baseline] (652.261 µs) : 0, 652
Remote Config [candidate] (665.304 µs) : 0, 665
Telemetry [baseline] (5.953 ms) : 0, 5953
Telemetry [candidate] (5.365 ms) : 0, 5365
ProfilingAgent [baseline] (76.002 ms) : 0, 76002
ProfilingAgent [candidate] (75.634 ms) : 0, 75634
Profiling [baseline] (76.028 ms) : 0, 76028
Profiling [candidate] (75.658 ms) : 0, 75658
Startup time reports for petclinicgantt
title petclinic - global startup overhead: candidate=1.20.0-SNAPSHOT~1d67af6510, baseline=1.20.0-SNAPSHOT~cbe55c2700
dateFormat X
axisFormat %s
section tracing
Agent [baseline] (987.686 ms) : 0, 987686
Total [baseline] (9.221 s) : 0, 9220798
Agent [candidate] (983.216 ms) : 0, 983216
Total [candidate] (9.177 s) : 0, 9177476
section appsec
Agent [baseline] (1.07 s) : 0, 1070343
Total [baseline] (9.244 s) : 0, 9243765
Agent [candidate] (1.069 s) : 0, 1068918
Total [candidate] (9.256 s) : 0, 9256270
section iast
Agent [baseline] (1.094 s) : 0, 1094111
Total [baseline] (9.415 s) : 0, 9414545
Agent [candidate] (1.084 s) : 0, 1083577
Total [candidate] (9.416 s) : 0, 9416187
section profiling
Agent [baseline] (1.157 s) : 0, 1157238
Total [baseline] (9.483 s) : 0, 9482996
Agent [candidate] (1.157 s) : 0, 1156701
Total [candidate] (9.46 s) : 0, 9459958
gantt
title petclinic - break down per module: candidate=1.20.0-SNAPSHOT~1d67af6510, baseline=1.20.0-SNAPSHOT~cbe55c2700
dateFormat X
axisFormat %s
section tracing
BytebuddyAgent [baseline] (612.21 ms) : 0, 612210
BytebuddyAgent [candidate] (608.751 ms) : 0, 608751
GlobalTracer [baseline] (284.492 ms) : 0, 284492
GlobalTracer [candidate] (283.752 ms) : 0, 283752
AppSec [baseline] (49.94 ms) : 0, 49940
AppSec [candidate] (50.575 ms) : 0, 50575
Remote Config [baseline] (665.082 µs) : 0, 665
Remote Config [candidate] (663.5 µs) : 0, 664
Telemetry [baseline] (6.027 ms) : 0, 6027
Telemetry [candidate] (5.354 ms) : 0, 5354
section appsec
BytebuddyAgent [baseline] (610.878 ms) : 0, 610878
BytebuddyAgent [candidate] (609.453 ms) : 0, 609453
GlobalTracer [baseline] (283.382 ms) : 0, 283382
GlobalTracer [candidate] (283.877 ms) : 0, 283877
AppSec [baseline] (135.417 ms) : 0, 135417
AppSec [candidate] (135.572 ms) : 0, 135572
Remote Config [baseline] (729.884 µs) : 0, 730
Remote Config [candidate] (727.06 µs) : 0, 727
Telemetry [baseline] (5.715 ms) : 0, 5715
Telemetry [candidate] (5.139 ms) : 0, 5139
section iast
BytebuddyAgent [baseline] (721.277 ms) : 0, 721277
BytebuddyAgent [candidate] (711.129 ms) : 0, 711129
GlobalTracer [baseline] (271.039 ms) : 0, 271039
GlobalTracer [candidate] (271.736 ms) : 0, 271736
AppSec [baseline] (47.295 ms) : 0, 47295
AppSec [candidate] (47.09 ms) : 0, 47090
Remote Config [baseline] (548.459 µs) : 0, 548
Remote Config [candidate] (637.519 µs) : 0, 638
Telemetry [baseline] (5.665 ms) : 0, 5665
Telemetry [candidate] (5.499 ms) : 0, 5499
IAST [baseline] (13.842 ms) : 0, 13842
IAST [candidate] (13.233 ms) : 0, 13233
section profiling
BytebuddyAgent [baseline] (624.523 ms) : 0, 624523
BytebuddyAgent [candidate] (624.506 ms) : 0, 624506
GlobalTracer [baseline] (345.772 ms) : 0, 345772
GlobalTracer [candidate] (347.892 ms) : 0, 347892
AppSec [baseline] (49.067 ms) : 0, 49067
AppSec [candidate] (49.313 ms) : 0, 49313
Remote Config [baseline] (650.028 µs) : 0, 650
Remote Config [candidate] (659.7 µs) : 0, 660
Telemetry [baseline] (5.968 ms) : 0, 5968
Telemetry [candidate] (5.367 ms) : 0, 5367
ProfilingAgent [baseline] (78.335 ms) : 0, 78335
ProfilingAgent [candidate] (75.897 ms) : 0, 75897
Profiling [baseline] (78.361 ms) : 0, 78361
Profiling [candidate] (75.922 ms) : 0, 75922
LoadParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 24 cases. Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.20.0-SNAPSHOT~1d67af6510, baseline=1.20.0-SNAPSHOT~cbe55c2700
dateFormat X
axisFormat %s
section baseline
no_agent (359.127 µs) : 339, 379
. : milestone, 359,
appsec (666.254 µs) : 645, 688
. : milestone, 666,
iast (447.281 µs) : 427, 468
. : milestone, 447,
iast_FULL (525.408 µs) : 505, 546
. : milestone, 525,
iast_INACTIVE (436.025 µs) : 415, 457
. : milestone, 436,
profiling (440.444 µs) : 419, 462
. : milestone, 440,
tracing (427.992 µs) : 407, 449
. : milestone, 428,
section candidate
no_agent (364.894 µs) : 344, 385
. : milestone, 365,
appsec (657.121 µs) : 637, 677
. : milestone, 657,
iast (459.686 µs) : 438, 481
. : milestone, 460,
iast_FULL (519.984 µs) : 499, 541
. : milestone, 520,
iast_INACTIVE (439.003 µs) : 418, 460
. : milestone, 439,
profiling (438.068 µs) : 417, 459
. : milestone, 438,
tracing (432.879 µs) : 412, 453
. : milestone, 433,
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.20.0-SNAPSHOT~1d67af6510, baseline=1.20.0-SNAPSHOT~cbe55c2700
dateFormat X
axisFormat %s
section baseline
no_agent (1.322 ms) : 1302, 1341
. : milestone, 1322,
appsec (1.671 ms) : 1647, 1695
. : milestone, 1671,
iast (1.431 ms) : 1407, 1456
. : milestone, 1431,
profiling (1.472 ms) : 1447, 1497
. : milestone, 1472,
tracing (1.443 ms) : 1419, 1467
. : milestone, 1443,
section candidate
no_agent (1.343 ms) : 1324, 1362
. : milestone, 1343,
appsec (1.698 ms) : 1674, 1722
. : milestone, 1698,
iast (1.448 ms) : 1423, 1473
. : milestone, 1448,
profiling (1.438 ms) : 1414, 1463
. : milestone, 1438,
tracing (1.437 ms) : 1413, 1461
. : milestone, 1437,
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What Does This Do
Under some circumstances, the
namefield of an IAST source can benull(very rare, and generally an indicative of another issue, but it's currently legal). In this case, the unvalidated redirect detection can throw a NPE.This NPE is caught in the instrumentation, so it will not break the app, but it will log to debug
Motivation
Additional Notes
Backport of #5755