Skip to content

Commit fddb0d2

Browse files
committed
authhelper: set referer on verification
Signed-off-by: Simon Bennetts <[email protected]>
1 parent ae2927a commit fddb0d2

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

addOns/authhelper/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
- Support for tracking authorization headers automatically for Header based auth.
1111
- Add Authentication Report section for the log file.
1212

13+
## Changed
14+
- Send the referer header on verification if set on the original request.
15+
1316
### Fixed
1417
- Do not fail the authentication on diagnostic errors.
1518

addOns/authhelper/src/main/java/org/zaproxy/addon/authhelper/VerificationDetectionProcessor.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,26 @@ private synchronized void updateContext(String loggedInIndicator, String loggedO
136136
authMethod.setLoggedOutIndicatorPattern(loggedOutIndicator);
137137
authMethod.setPollData(details.getMsg().getRequestBody().toString());
138138

139-
String contentType = details.getMsg().getRequestHeader().getHeader(HttpHeader.CONTENT_TYPE);
140-
if (contentType != null) {
141-
authMethod.setPollHeaders(HttpHeader.CONTENT_TYPE + ": " + contentType);
139+
StringBuilder sb = new StringBuilder();
140+
appendHeader(sb, details.getMsg().getRequestHeader(), HttpHeader.CONTENT_TYPE);
141+
appendHeader(sb, details.getMsg().getRequestHeader(), HttpHeader.REFERER);
142+
if (!sb.isEmpty()) {
143+
authMethod.setPollHeaders(sb.toString());
142144
}
143145
AuthUtils.setVerificationDetailsForContext(context.getId(), details);
144146
Stats.incCounter("stats.auth.configure.verification");
145147
}
146148

149+
private void appendHeader(StringBuilder sb, HttpRequestHeader reqHeader, String headerName) {
150+
String headerValue = reqHeader.getHeader(headerName);
151+
if (headerValue != null) {
152+
sb.append(headerName);
153+
sb.append(": ");
154+
sb.append(headerValue);
155+
sb.append("\n");
156+
}
157+
}
158+
147159
private VerificationRequestDetails repeatRequest(VerificationRequestDetails vrd, boolean auth)
148160
throws IOException {
149161
HttpMessage msg;
@@ -161,6 +173,10 @@ private VerificationRequestDetails repeatRequest(VerificationRequestDetails vrd,
161173
.setHeader(
162174
HttpRequestHeader.CONTENT_TYPE,
163175
origReqHeader.getHeader(HttpRequestHeader.CONTENT_TYPE));
176+
msg.getRequestHeader()
177+
.setHeader(
178+
HttpRequestHeader.REFERER,
179+
origReqHeader.getHeader(HttpRequestHeader.REFERER));
164180

165181
msg.getRequestBody().setBody(vrd.getMsg().getRequestBody().getBytes());
166182
msg.getRequestHeader().setContentLength(msg.getRequestBody().length());

addOns/automation/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7-
7+
### Fixed
8+
- Bug in handling headers with colons in the values.
89

910
## [0.51.0] - 2025-07-17
1011
### Added

addOns/automation/src/main/java/org/zaproxy/addon/automation/VerificationData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public VerificationData(Context context) {
104104
if (headers != null) {
105105
List<AdditionalHeaderData> headerList = new ArrayList<>();
106106
for (String header : headers.split("\n")) {
107-
String[] headerValue = header.split(":");
107+
String[] headerValue = header.split(":", 2);
108108
if (headerValue.length == 2) {
109109
headerList.add(
110110
new AdditionalHeaderData(headerValue[0].trim(), headerValue[1].trim()));

addOns/automation/src/test/java/org/zaproxy/addon/automation/VerificationDataUnitTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.zaproxy.addon.automation;
2121

2222
import static org.hamcrest.MatcherAssert.assertThat;
23+
import static org.hamcrest.Matchers.hasSize;
2324
import static org.hamcrest.Matchers.is;
2425
import static org.junit.jupiter.params.provider.Arguments.arguments;
2526
import static org.mockito.BDDMockito.given;
@@ -28,6 +29,7 @@
2829
import java.util.LinkedHashMap;
2930
import java.util.Locale;
3031
import java.util.stream.Stream;
32+
import org.junit.jupiter.api.Test;
3133
import org.junit.jupiter.params.ParameterizedTest;
3234
import org.junit.jupiter.params.provider.Arguments;
3335
import org.junit.jupiter.params.provider.MethodSource;
@@ -72,4 +74,25 @@ void shouldSetCorrectAuthenticationMethod(
7274
context.getAuthenticationMethod().getAuthCheckingStrategy(),
7375
is(authCheckingStrategy));
7476
}
77+
78+
@Test
79+
void shouldHandleContextWithHeaders() {
80+
// Given
81+
Constant.messages = new I18N(Locale.ENGLISH);
82+
Context context = mock(Context.class);
83+
HttpAuthenticationMethod httpAuthMethod = new HttpAuthenticationMethod();
84+
given(context.getAuthenticationMethod()).willReturn(httpAuthMethod);
85+
httpAuthMethod.setPollHeaders("test-header1: value1\n referer : https://www.example.com ");
86+
87+
// When
88+
VerificationData data = new VerificationData(context);
89+
90+
// Then
91+
assertThat(data.getPollAdditionalHeaders(), hasSize(2));
92+
assertThat(data.getPollAdditionalHeaders().get(0).getHeader(), is("test-header1"));
93+
assertThat(data.getPollAdditionalHeaders().get(0).getValue(), is("value1"));
94+
assertThat(data.getPollAdditionalHeaders().get(1).getHeader(), is("referer"));
95+
assertThat(
96+
data.getPollAdditionalHeaders().get(1).getValue(), is("https://www.example.com"));
97+
}
7598
}

0 commit comments

Comments
 (0)