Skip to content

fix(security): strip CR/LF from response headers, validate redirects, contain uploads (Snyk) - #499

Merged
kunal0137 merged 4 commits into
devfrom
fix-snyk-headers-redirects
Nov 25, 2026
Merged

kunal0137 merged 4 commits into
devfrom
fix-snyk-headers-redirects

Conversation

@kunal0137

@kunal0137 kunal0137 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes the Snyk Code rows in Monolith that were waiting on #427, #430 and #429. This branch starts fresh from current dev; those PRs were read as reference only.

  • Response headers (CRLF): one helper, WebUtility.responseHeaderValue, strips CR, LF and NUL from redirect, Content-Disposition and Set-Cookie header values in the filters and resources.
  • Redirects: new RedirectUtility.
    • allowedReturnUrl accepts a relative path, this request's origin, the application URL, the origin of social.properties redirect, origins in a new optional redirect_allowed_origins (comma list), or a WHITE_LIST_DOMAINS domain. It is applied, as one policy, to the login redirect param (request and session, checked raw), the IdpSSOServlet redirect param, the SSOFilter referer and the SAML RelayState redirect.
    • sendLocalRedirect sends root-relative redirects for share-session links and the no-user page, so the host never comes from the request.
    • The SAML login pages and setAdmin now navigate to relative sibling paths instead of URLs built from location.
  • Uploads: the final upload target is normalized, then resolved inside the upload folder with WebUtility.resolveWithin; . and .. names are refused.
  • False positives: 16 rows, mostly session values the server sets itself and server-built paths or URLs. The reasons are prepared and will go to Snyk as ignores after this merges.

Behaviour changes

  • A login or SAML redirect to any other origin is refused (logged). Before, an empty WHITE_LIST_DOMAINS meant any URL was accepted. Deployments whose UI origin differs from both the Monolith host and social.properties redirect need redirect_allowed_origins. A refused login redirect falls back to the default; a refused IdpSSOServlet redirect returns 403.
  • Share-session redirects (GET 302, POST 307) are root-relative instead of absolute URLs built from the request Host.

Testing

  • Full Monolith test suite: 2030 tests pass. Existing share-session, no-user, SSO and SAML tests updated for root-relative redirects and origin checks.
  • Local lane with this branch: clean start, /api/config 200.
  • IdpSSOServlet with https://evil.example.com, //evil.example.com and javascript: returns 403; relative and same-host values pass.
  • RedirectUtility was checked against relative, same-host, configured-origin, host-suffix, //host, /\\host, userinfo and CRLF cases.
  • Upload: normal files and subfolders work; path=../../x is refused.
  • Not run live: share-session links and the post-login custom redirect (no share token or login on the lane).

@snyk-io

snyk-io Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

- one redirect policy in IdpSSOServlet (drop the second domain check)
- RedirectUtility: same origin instead of same host, also the application url;
  null-safe social.properties reads; strip all control characters (tab) and
  always set a root-relative Location
- check redirect params and the referer raw instead of html-encoded
- SamlVerifierServlet follows RelayState only to an allowed destination
- uploads: normalize before the containment check and refuse . and .. names
- update the filter and SAML tests for root-relative redirects
- containedUploadFile compares Path values, so Windows separators no longer
  reject every upload
- the client file name is reduced to its base name and normalized before the
  uniqueness check; the reply uses the name actually written
- SamlVerifierServlet sends the stored redirect without html-encoding it, so
  deep links keep their query strings
@kunal0137
kunal0137 marked this pull request as ready for review November 25, 2026 19:13
@kunal0137
kunal0137 requested a review from a team as a code owner November 25, 2026 19:13
@kunal0137
kunal0137 merged commit 0b04c30 into dev Nov 25, 2026
6 checks passed
@kunal0137
kunal0137 deleted the fix-snyk-headers-redirects branch November 25, 2026 19:14
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.

1 participant