Skip to content

Commit

Permalink
ZCS-8246 Fixing NPE with CSRF check (#987)
Browse files Browse the repository at this point in the history
* ZCS-8246 Fixing NPE with CSRF check

* ZCS-8246 Code review comments
  • Loading branch information
rupalid authored Nov 29, 2019
1 parent 0cade97 commit e5cf669
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions store/src/java-test/com/zimbra/cs/servlet/util/CsrfUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ public final void testIsValidCsrfTokenForAccountWithMultipleTokens() {
}
}

@Test
public final void testIsValidCsrfTokenForAccountWithNullAuthToken() {
try {
Account acct = Provisioning.getInstance().getAccountByName(
"[email protected]");
AuthToken authToken = new ZimbraAuthToken(acct);

String csrfToken1 = CsrfUtil.generateCsrfToken(acct.getId(),
AUTH_TOKEN_EXPR, CSRFTOKEN_SALT, authToken);
boolean validToken = CsrfUtil.isValidCsrfToken(csrfToken1, null);
assertEquals(false, validToken);


} catch (Exception e) {
fail("Should not throw exception.");
}
}


@Test
public final void testIsCsrfRequestWhenCsrfCheckIsTurnedOn() {
Expand Down
2 changes: 1 addition & 1 deletion store/src/java/com/zimbra/cs/servlet/util/CsrfUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static Account getAccount(AuthToken authToken, boolean loadFromLdap) thro
}

public static boolean isValidCsrfToken(String csrfToken, AuthToken authToken) {
if (StringUtil.isNullOrEmpty(csrfToken)) {
if (StringUtil.isNullOrEmpty(csrfToken) || null == authToken) {
return false;
}

Expand Down

0 comments on commit e5cf669

Please sign in to comment.