Skip to content

Commit 2a1a5a5

Browse files
committed
authhelper: skip logout statements in CSA
Disable the statements after the logout comment in the CSA scripts. Signed-off-by: thc202 <[email protected]>
1 parent c1b7f94 commit 2a1a5a5

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
import org.zaproxy.zap.users.User;
9292
import org.zaproxy.zap.utils.Pair;
9393
import org.zaproxy.zap.utils.Stats;
94+
import org.zaproxy.zest.core.v1.ZestComment;
95+
import org.zaproxy.zest.core.v1.ZestScript;
96+
import org.zaproxy.zest.core.v1.ZestStatement;
9497

9598
public class AuthUtils {
9699

@@ -146,6 +149,8 @@ public class AuthUtils {
146149

147150
private static final String INPUT_TAG = "input";
148151

152+
private static final String RECORDING_LOGOUT = "ZAP Recording LOGOUT";
153+
149154
private static final HttpRequestConfig REDIRECT_NOTIFIER_CONFIG =
150155
HttpRequestConfig.builder()
151156
.setRedirectionValidator(
@@ -1362,4 +1367,16 @@ public static boolean isRelevantToAuthDiags(HttpMessage msg) {
13621367
|| host.contains("mozilla")
13631368
|| host.contains("safebrowsing-cache"));
13641369
}
1370+
1371+
public static void disableLogoutStatements(ZestScript zestScript) {
1372+
boolean disable = false;
1373+
for (ZestStatement stmt : zestScript.getStatements()) {
1374+
if (disable) {
1375+
stmt.setEnabled(false);
1376+
} else if (stmt instanceof ZestComment comment
1377+
&& RECORDING_LOGOUT.equals(comment.getComment())) {
1378+
disable = true;
1379+
}
1380+
}
1381+
}
13651382
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void insertDiagnostics(ZestScript zestScript) {
149149

150150
for (int i = 0; i < zestScript.getStatements().size(); i++) {
151151
ZestStatement stmt = zestScript.getStatements().get(i);
152-
if (stmt instanceof ZestClientElementClear) {
152+
if (!stmt.isEnabled() || stmt instanceof ZestClientElementClear) {
153153
continue;
154154
}
155155

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ public WebSession authenticate(
414414
zestScript.add(
415415
new ZestActionSleep(TimeUnit.SECONDS.toMillis(getLoginPageWait())));
416416
removeCloseStatements(zestScript);
417+
AuthUtils.disableLogoutStatements(zestScript);
417418
} else {
418419
LOGGER.warn("Expected authScript to be a Zest script");
419420
return null;

addOns/authhelper/src/main/java/org/zaproxy/addon/authhelper/internal/AuthenticationBrowserHook.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void browserLaunched(SeleniumScriptUtils ssUtils) {
8181
paramsValues.put(USERNAME, credentials.getParam(USERNAME));
8282
paramsValues.put(PASSWORD, credentials.getParam(PASSWORD));
8383
ZestScript zs = csaMethod.getZestScript();
84+
AuthUtils.disableLogoutStatements(zs);
8485
runner.setup(user, zs);
8586
runner.run(zs, paramsValues);
8687

addOns/authhelper/src/test/java/org/zaproxy/addon/authhelper/AuthUtilsUnitTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
import org.zaproxy.zap.testutils.TestUtils;
9494
import org.zaproxy.zap.users.User;
9595
import org.zaproxy.zap.utils.Pair;
96+
import org.zaproxy.zest.core.v1.ZestActionPrint;
97+
import org.zaproxy.zest.core.v1.ZestComment;
98+
import org.zaproxy.zest.core.v1.ZestScript;
9699

97100
class AuthUtilsUnitTest extends TestUtils {
98101

@@ -983,6 +986,43 @@ void shouldReportRelevantResponseHeaderTypeToAuthDiags(String type, String resul
983986
assertThat(res, is(equalTo(Boolean.parseBoolean(result))));
984987
}
985988

989+
@Test
990+
void shouldDisableLogoutStatements() {
991+
// Given
992+
ZestScript zs = new ZestScript();
993+
zs.add(new ZestActionPrint());
994+
zs.add(new ZestActionPrint());
995+
zs.add(new ZestComment("ZAP Recording LOGOUT"));
996+
zs.add(new ZestActionPrint());
997+
zs.add(new ZestActionPrint());
998+
999+
// When
1000+
AuthUtils.disableLogoutStatements(zs);
1001+
1002+
// Then
1003+
assertThat(zs.getStatements().get(0).isEnabled(), is(equalTo(true)));
1004+
assertThat(zs.getStatements().get(1).isEnabled(), is(equalTo(true)));
1005+
assertThat(zs.getStatements().get(2).isEnabled(), is(equalTo(true)));
1006+
assertThat(zs.getStatements().get(3).isEnabled(), is(equalTo(false)));
1007+
assertThat(zs.getStatements().get(4).isEnabled(), is(equalTo(false)));
1008+
}
1009+
1010+
@Test
1011+
void shouldNotDisableStatementsWhenNoLogoutCommentPresent() {
1012+
// Given
1013+
ZestScript zs = new ZestScript();
1014+
zs.add(new ZestActionPrint());
1015+
zs.add(new ZestActionPrint());
1016+
zs.add(new ZestActionPrint());
1017+
zs.add(new ZestActionPrint());
1018+
1019+
// When
1020+
AuthUtils.disableLogoutStatements(zs);
1021+
1022+
// Then
1023+
zs.getStatements().forEach(e -> assertThat(e.isEnabled(), is(equalTo(true))));
1024+
}
1025+
9861026
static class BrowserTest extends TestUtils {
9871027

9881028
private static final String HTML_SHADOM_DOM =

0 commit comments

Comments
 (0)