Skip to content

Commit 8a7c26f

Browse files
authored
Merge pull request #6679 from thc202/csa-proxy-error
Fix proxy errors during CSA
2 parents 24b9939 + b991ee1 commit 8a7c26f

5 files changed

Lines changed: 46 additions & 11 deletions

File tree

addOns/authhelper/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
- Support for min wait for time in Client Script Authentication.
1414

1515
## Changed
16-
- Now depends on minimum Common Library version 1.35.0.
16+
- Now depends on minimum Common Library version 1.35.0 and Zest version 48.9.0.
1717
- Send the referer header on verification if set on the original request.
1818
- Removed requirement to set at least one header in the GUI for Header-Based Session Management.
1919
- Include step for errors in the authentication diagnostics.
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2626
- Do not fail the authentication on diagnostic errors.
2727
- Do not configure poll authentication verification without logged in indicator.
2828
- Handle errors collecting the browser storage diagnostics.
29+
- Fix proxy errors during authentication with Client Script Based Authentication.
2930

3031
## [0.27.0] - 2025-07-03
3132
### Added

addOns/authhelper/authhelper.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ zapAddOn {
7171
version.set("15.*")
7272
}
7373
register("zest") {
74-
version.set(">=48.8.0")
74+
version.set(">=48.9.0")
7575
}
7676
}
7777
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ public WebSession authenticate(
450450
return null;
451451
}
452452

453+
zestRunner.setAutoCloseProxy(false);
453454
zestRunner.registerHandler(getHandler(user));
454455
zestScript.add(
455456
new ZestActionSleep(TimeUnit.SECONDS.toMillis(getLoginPageWait())));
@@ -597,6 +598,7 @@ public WebSession authenticate(
597598
// Ignore
598599
}
599600
});
601+
zestRunner.closeProxy();
600602
}
601603
}
602604
}

addOns/zest/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8-
8+
### Changed
9+
- Allow to keep auhtenticator's proxy running after the authentication.
910

1011
## [48.8.0] - 2025-07-03
1112

addOns/zest/src/main/java/org/zaproxy/zap/extension/zest/ZestAuthenticationRunner.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public class ZestAuthenticationRunner extends ZestZapRunner implements Authentic
6868
private ZestScriptWrapper script = null;
6969
private AuthenticationHelper helper;
7070

71+
private boolean autoCloseProxy;
72+
private Server proxyServer;
73+
7174
public ZestAuthenticationRunner(
7275
ExtensionZest extension, ExtensionNetwork extensionNetwork, ZestScriptWrapper script) {
7376
super(extension, extensionNetwork, script);
@@ -76,6 +79,7 @@ public ZestAuthenticationRunner(
7679
script.getZestScript().getParameters().getTokenStart()
7780
+ TOTP_VAR_NAME
7881
+ script.getZestScript().getParameters().getTokenEnd();
82+
autoCloseProxy = true;
7983
}
8084

8185
@Override
@@ -127,10 +131,9 @@ public HttpMessage authenticate(
127131
Map<String, String> paramsValues,
128132
GenericAuthenticationCredentials credentials)
129133
throws ScriptException {
130-
134+
closeProxy();
131135
this.helper = helper;
132136

133-
Server proxyServer = null;
134137
try {
135138
if (hasClientStatements()) {
136139
proxyServer =
@@ -174,13 +177,41 @@ public HttpMessage authenticate(
174177
} catch (Exception e) {
175178
throw new ScriptException(e);
176179
} finally {
177-
if (proxyServer != null) {
178-
try {
179-
proxyServer.close();
180-
} catch (IOException e) {
181-
LOGGER.debug("An error occurred while stopping the proxy.", e);
182-
}
180+
if (autoCloseProxy) {
181+
closeProxy();
182+
}
183+
}
184+
}
185+
186+
/**
187+
* Sets whether or not the proxy created for the authentication should be automatically closed
188+
* after the authentication, true by default.
189+
*
190+
* <p>Allows to use the browser after the authentication has finished, callers should close the
191+
* proxy once no longer needed.
192+
*
193+
* @param autoCloseProxy {@code true} to auto close the proxy, {@code false} otherwise.
194+
* @since 48.9.0
195+
* @see #closeProxy()
196+
*/
197+
public void setAutoCloseProxy(boolean autoCloseProxy) {
198+
this.autoCloseProxy = autoCloseProxy;
199+
}
200+
201+
/**
202+
* Closes the proxy.
203+
*
204+
* @since 48.9.0
205+
* @see #setAutoCloseProxy(boolean)
206+
*/
207+
public void closeProxy() {
208+
if (proxyServer != null) {
209+
try {
210+
proxyServer.close();
211+
} catch (IOException e) {
212+
LOGGER.debug("An error occurred while stopping the proxy.", e);
183213
}
214+
proxyServer = null;
184215
}
185216
}
186217

0 commit comments

Comments
 (0)