Skip to content

Commit 35abdf1

Browse files
committed
remove block waf
1 parent 9e4cfe6 commit 35abdf1

File tree

2 files changed

+3
-53
lines changed

2 files changed

+3
-53
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/api/security/ApiSecuritySamplerImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,12 @@ public boolean preSampleRequest(final @Nonnull AppSecRequestContext ctx) {
6161

6262
// If route is absent, use http.endpoint as fallback (RFC-1076)
6363
if (route == null) {
64-
// Don't sample blocked requests - they represent attacks, not valid API endpoints
65-
if (ctx.isWafBlocked()) {
66-
return false;
67-
}
6864
final int statusCode = ctx.getResponseStatus();
6965
// Don't use endpoint for 404 responses as a failsafe
7066
if (statusCode == 404) {
7167
return false;
7268
}
73-
// Try to get or compute the endpoint
69+
// Try to get or compute the endpoint (computed once and cached)
7470
route = ctx.getOrComputeEndpoint();
7571
if (route == null) {
7672
return false;

dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/api/security/ApiSecuritySamplerTest.groovy

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -117,51 +117,20 @@ class ApiSecuritySamplerTest extends DDSpecification {
117117
!preSampled
118118
}
119119

120-
void 'preSampleRequest with null route and blocked request does not sample'() {
121-
given:
122-
def ctx = createContextWithUrl(null, 'GET', 403, 'http://localhost:8080/admin/users')
123-
ctx.setWafBlocked() // Request was blocked by AppSec
124-
def sampler = new ApiSecuritySamplerImpl()
125-
126-
when:
127-
def preSampled = sampler.preSampleRequest(ctx)
128-
129-
then:
130-
!preSampled // Blocked requests should not be sampled
131-
}
132-
133-
void 'preSampleRequest with null route and 403 non-blocked API does sample'() {
120+
void 'preSampleRequest with null route and non-404 status does sample'() {
134121
given:
135122
def ctx = createContextWithUrl(null, 'GET', 403, 'http://localhost:8080/api/forbidden-resource')
136-
// NOT calling setWafBlocked() - this is a legitimate API that returns 403
137123
def sampler = new ApiSecuritySamplerImpl()
138124

139125
when:
140126
def preSampled = sampler.preSampleRequest(ctx)
141127

142128
then:
143-
preSampled // Legitimate APIs that return 403 should be sampled
129+
preSampled // Non-404 responses should be sampled when endpoint is available
144130
ctx.getOrComputeEndpoint() != null
145131
ctx.getApiSecurityEndpointHash() != null
146132
}
147133

148-
void 'preSampleRequest with null route and blocked request with different status codes does not sample'() {
149-
given:
150-
def ctx200 = createContextWithUrl(null, 'GET', 200, 'http://localhost:8080/attack')
151-
ctx200.setWafBlocked()
152-
def ctx500 = createContextWithUrl(null, 'GET', 500, 'http://localhost:8080/attack')
153-
ctx500.setWafBlocked()
154-
def sampler = new ApiSecuritySamplerImpl()
155-
156-
when:
157-
def preSampled200 = sampler.preSampleRequest(ctx200)
158-
def preSampled500 = sampler.preSampleRequest(ctx500)
159-
160-
then:
161-
!preSampled200 // Blocked requests should not be sampled regardless of status code
162-
!preSampled500
163-
}
164-
165134
void 'second request with same endpoint is not sampled'() {
166135
given:
167136
def ctx1 = createContextWithUrl(null, 'GET', 200, 'http://localhost:8080/api/users/123')
@@ -596,21 +565,6 @@ class ApiSecuritySamplerTest extends DDSpecification {
596565
ctx.getApiSecurityEndpointHash() == null // But hash was never set because sampling failed
597566
}
598567

599-
void 'RFC-1076: blocked request with valid endpoint does not sample'() {
600-
given:
601-
def ctx = createContextWithUrl(null, 'POST', 403, 'http://localhost:8080/api/admin/users')
602-
ctx.setWafBlocked() // Request blocked by AppSec WAF
603-
def sampler = new ApiSecuritySamplerImpl()
604-
605-
when:
606-
def preSampled = sampler.preSampleRequest(ctx)
607-
608-
then:
609-
!preSampled
610-
// Blocked requests represent attacks, not legitimate API endpoints
611-
ctx.getApiSecurityEndpointHash() == null
612-
}
613-
614568
// Helper method to compute hash same way as ApiSecuritySamplerImpl
615569
private static long computeApiHash(final String route, final String method, final int statusCode) {
616570
long result = 17

0 commit comments

Comments
 (0)