Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZCS-12917: Fix "An unknown error has occurred" raised when zimbraMailURL is configured #791

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

k-kato
Copy link
Contributor

@k-kato k-kato commented Feb 1, 2023

Issue:
When zimbraMailURL is changed from / to /test/path, for example, and user accesses https://host/ (without the path), login fails with an error "An unknown error has occurred."

Steps:

  1. set zimbraMailURL to /test/path
  2. access https://host/
  3. login to Classic UI. It succeeds at this time. The URL changes to https://host/test/path/?client=advanced
  4. log out. The URL is https://host/test/path/?loginOp=logout
  5. access https://host/ without the path
  6. try to login, but it fails.

Easier way:

  1. set zimbraMailURL to /test/path
  2. access https://host/test/path
  3. access https://host/
  4. try to login, but it fails.

Root cause:
When login page accessed, ZM_LOGIN_CSRF is created on a browser. The path of the cookie depends on the access URL.

  • https://host -> the path of the cookie is /
  • https://host/test/path -> the path of the cookie is /test/path

When a browser has the both cookies, login from https://host fails because (param.login_csrf eq cookie.ZM_LOGIN_CSRF.value) returns false. cookie.ZM_LOGIN_CSRF refers a cookie for /test/path, not for /. Then it falls back to c:otherwise block.

at line 145
<c:when test="${(not empty param.login_csrf) && (param.login_csrf eq cookie.ZM_LOGIN_CSRF.value)}">
   // zm:login process
</c:when>
<c:otherwise>
	<!-- on failure of csrf show error to user -->
	<c:set var="errorCode" value="unknownError"/>
	<fmt:message var="errorMessage" key="unknownError"/>
</c:otherwise>

Fix:

  • Specify the path / explicitly for ZM_LOGIN_CSRF and ZM_TEST cookies

@secure-code-warrior-for-github

Micro-Learning Topic: Cross-site request forgery (Detected by phrase)

Matched on "CSRF"

What is this? (2min video)

Session-related but not session-based, this attack is based on the ability of an attacker to force an action on a user’s browser (commonly in the form of a POST request) to perform an unauthorized action on behalf of the user. This can often occur without the user even noticing it… or only noticing when it is too late. The root cause is that browsers automatically send session cookies with all requests to a given domain, regardless of where the source of the request came from, and the application server cannot differentiate between a request that came from pages it served or a request that came from an unrelated page.

Try a challenge in Secure Code Warrior

Helpful references

@k-kato k-kato changed the title ZCS-12917: changed to remove ZM_TEST and ZM_LOGIN_CSRF cookies first ZCS-12917: Fix "An unknown error has occurred" raised when zimbraMailURL is configured Feb 1, 2023
@k-kato
Copy link
Contributor Author

k-kato commented Feb 1, 2023

I found that ZM_LOGIN_CSRF cookie was not removed after login at line 154-156. I will fix it and update the PR.

@k-kato
Copy link
Contributor Author

k-kato commented Feb 1, 2023

I added a commit.
@silentsakky please review it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants