|
19 | 19 | */
|
20 | 20 | package org.zaproxy.zap.extension.ascanrulesBeta;
|
21 | 21 |
|
| 22 | +import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse; |
22 | 23 | import static org.hamcrest.MatcherAssert.assertThat;
|
23 | 24 | import static org.hamcrest.Matchers.equalTo;
|
| 25 | +import static org.hamcrest.Matchers.hasSize; |
24 | 26 | import static org.hamcrest.Matchers.is;
|
25 | 27 |
|
| 28 | +import fi.iki.elonen.NanoHTTPD; |
| 29 | +import fi.iki.elonen.NanoHTTPD.IHTTPSession; |
| 30 | +import fi.iki.elonen.NanoHTTPD.Response; |
26 | 31 | import java.util.Map;
|
| 32 | +import org.apache.commons.httpclient.URIException; |
27 | 33 | import org.junit.jupiter.api.Test;
|
| 34 | +import org.junit.jupiter.params.ParameterizedTest; |
| 35 | +import org.junit.jupiter.params.provider.ValueSource; |
| 36 | +import org.parosproxy.paros.network.HttpMalformedHeaderException; |
| 37 | +import org.parosproxy.paros.network.HttpMessage; |
28 | 38 | import org.zaproxy.addon.commonlib.CommonAlertTag;
|
| 39 | +import org.zaproxy.zap.testutils.NanoServerHandler; |
29 | 40 |
|
30 | 41 | class ProxyDisclosureScanRuleUnitTest extends ActiveScannerTest<ProxyDisclosureScanRule> {
|
31 | 42 |
|
@@ -57,4 +68,33 @@ void shouldReturnExpectedMappings() {
|
57 | 68 | tags.get(CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getTag()),
|
58 | 69 | is(equalTo(CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getValue())));
|
59 | 70 | }
|
| 71 | + |
| 72 | + @ParameterizedTest |
| 73 | + @ValueSource( |
| 74 | + strings = { |
| 75 | + "X-Forwarded-For: 76.69.54.171", "X-Forwarded-For: 127.0.0.1", |
| 76 | + "X-Forwarded-Host: api.test.glaypen.garnercorp.com", "X-Forwarded-Port: 443", |
| 77 | + "X-Forwarded-Proto: https", "X-Forwarded-Scheme: https" |
| 78 | + }) |
| 79 | + void shouldNotAlertIfOriginalHasXForwardContent(String header) |
| 80 | + throws HttpMalformedHeaderException, URIException { |
| 81 | + // Given |
| 82 | + String test = "/"; |
| 83 | + nano.addHandler( |
| 84 | + new NanoServerHandler(test) { |
| 85 | + |
| 86 | + @Override |
| 87 | + protected Response serve(IHTTPSession session) { |
| 88 | + String content = "<html>" + header + "</html>"; |
| 89 | + return newFixedLengthResponse( |
| 90 | + Response.Status.OK, NanoHTTPD.MIME_HTML, content); |
| 91 | + } |
| 92 | + }); |
| 93 | + HttpMessage msg = getHttpMessage(test); |
| 94 | + rule.init(msg, parent); |
| 95 | + // When |
| 96 | + rule.scan(); |
| 97 | + // Then |
| 98 | + assertThat(alertsRaised, hasSize(equalTo(0))); // No messages sent |
| 99 | + } |
60 | 100 | }
|
0 commit comments