Skip to content

Commit 44b000e

Browse files
committed
ascanrulesBeta: Address possible FP in proxy detection rule
- CHANGELOG > Added change note. - ascanbeta.html > added note about the new condition. - ProxyDisclosureScanRule > Added condition to skip messages if they have an "x-forward" type header to start with. - ProxyDisclosureScanRuleUnitTest > Added a test to assert the new behavior. Signed-off-by: kingthorin <[email protected]>
1 parent d34392d commit 44b000e

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

addOns/ascanrulesBeta/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
## Unreleased
77
### Changed
88
- Log exception details in Out of Band XSS scan rule.
9+
- The Proxy Disclosure scan rule will no longer process messages that have an X-Forward type header to start with, in order to reduce possible false positives (Issue 8556).
910

1011
## [55] - 2024-09-02
1112
### Changed

addOns/ascanrulesBeta/src/main/java/org/zaproxy/zap/extension/ascanrulesBeta/ProxyDisclosureScanRule.java

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.regex.Pattern;
3333
import org.apache.commons.httpclient.URI;
3434
import org.apache.commons.lang3.RandomStringUtils;
35+
import org.apache.commons.lang3.StringUtils;
3536
import org.apache.logging.log4j.LogManager;
3637
import org.apache.logging.log4j.Logger;
3738
import org.parosproxy.paros.Constant;
@@ -193,6 +194,11 @@ public void init() {
193194
@Override
194195
public void scan() {
195196
try {
197+
if (StringUtils.containsIgnoreCase(
198+
getBaseMsg().getRequestHeader().getHeadersAsString(), "x-forward")) {
199+
// If it has an x-forward type header to start with just skip it
200+
return;
201+
}
196202
// where's what we're going to do (roughly):
197203
// 1: If TRACE is enabled on the origin web server, we're going to use it, and the
198204
// "Max-Forwards" header to verify

addOns/ascanrulesBeta/src/main/javahelp/org/zaproxy/zap/extension/ascanrulesBeta/resources/help/contents/ascanbeta.html

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ <H2 id="id-40025">Proxy Disclosure</H2>
136136
<li>The presence or absence of any proxy-based components that might cause attacks against the application to be detected, prevented, or mitigated.</li>
137137
</ul>
138138
<p>
139+
Note: The rule will skip HTTP messages that have an "X-Foward" type header to start with (in order to reduce possible false positives).
140+
<p>
139141
Latest code: <a href="https://github.com/zaproxy/zap-extensions/blob/main/addOns/ascanrulesBeta/src/main/java/org/zaproxy/zap/extension/ascanrulesBeta/ProxyDisclosureScanRule.java">ProxyDisclosureScanRule.java</a>
140142
<br>
141143
Alert ID: <a href="https://www.zaproxy.org/docs/alerts/40025/">40025</a>.

addOns/ascanrulesBeta/src/test/java/org/zaproxy/zap/extension/ascanrulesBeta/ProxyDisclosureScanRuleUnitTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121

2222
import static org.hamcrest.MatcherAssert.assertThat;
2323
import static org.hamcrest.Matchers.equalTo;
24+
import static org.hamcrest.Matchers.hasSize;
2425
import static org.hamcrest.Matchers.is;
2526

2627
import java.util.Map;
28+
import org.apache.commons.httpclient.URI;
29+
import org.apache.commons.httpclient.URIException;
2730
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.params.provider.CsvSource;
33+
import org.parosproxy.paros.network.HttpMalformedHeaderException;
34+
import org.parosproxy.paros.network.HttpMessage;
2835
import org.zaproxy.addon.commonlib.CommonAlertTag;
2936

3037
class ProxyDisclosureScanRuleUnitTest extends ActiveScannerTest<ProxyDisclosureScanRule> {
@@ -57,4 +64,22 @@ void shouldReturnExpectedMappings() {
5764
tags.get(CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getTag()),
5865
is(equalTo(CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getValue())));
5966
}
67+
68+
@ParameterizedTest
69+
@CsvSource({
70+
"X-Forwarded-For,76.69.54.171", "\"X-Forwarded-For,127.0.0.1",
71+
"X-Forwarded-Host,api.test.glaypen.garnercorp.com", "X-Forwarded-Port,443",
72+
"X-Forwarded-Proto:,https", "X-Forwarded-Scheme,https"
73+
})
74+
void shouldNotProcessIfOriginalHasXForwardHeader(String header, String value)
75+
throws HttpMalformedHeaderException, URIException {
76+
// Given
77+
HttpMessage msg = new HttpMessage(new URI("https://example.org", false));
78+
msg.getRequestHeader().addHeader(header, value);
79+
rule.init(msg, parent);
80+
// When
81+
rule.scan();
82+
// Then
83+
assertThat(httpMessagesSent, hasSize(equalTo(0))); // No messages sent
84+
}
6085
}

0 commit comments

Comments
 (0)