Skip to content

fix(security): prevent open redirect from user-controlled data (SonarQube jssecurity:S5146) - #228

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/sonarqube-fix-AZhSVLrd4wErqc9Ey1Y4-1787562251
Open

fix(security): prevent open redirect from user-controlled data (SonarQube jssecurity:S5146)#228
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/sonarqube-fix-AZhSVLrd4wErqc9Ey1Y4-1787562251

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 24, 2026

Copy link
Copy Markdown

Summary

adminLoginSuccess in routes/index.js redirected straight to redirectPage, which comes from req.body.redirectPage on the admin login POST. An attacker could send a victim to /login?redirectPage=https://evil.[REDACTED SECRET] (or //evil.[REDACTED SECRET]) and have the app bounce them off-site after login — a classic open redirect used for phishing/credential harvesting.

Fix restricts the target to same-origin relative paths only, falling back to /admin:

function isSafeRedirectPath(redirectPage) {
  return typeof redirectPage === 'string' &&
    /^\/[^/\\]/.test(redirectPage) &&
    !redirectPage.includes('\\')
}
// if (redirectPage)            -> res.redirect(redirectPage)
// if (isSafeRedirectPath(...)) -> res.redirect(redirectPage) else res.redirect('/admin')

This rejects absolute URLs (https://evil.[REDACTED SECRET]), protocol-relative URLs (//evil.[REDACTED SECRET]) and backslash variants (/\evil.[REDACTED SECRET]) that some browsers normalize to a host.

SonarQube issue: AZhSVLrd4wErqc9Ey1Y4 — rule jssecurity:S5146, routes/index.js:61, severity BLOCKER. No other code was touched.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/b20590b053fc45e69fc0f66ee592c206
Requested by: @joao-cognition


Note

Devin errored when opening this Pull Request as joao-cognition.
As a fallback, Devin opened this PR as itself.


Devin Review

Status Commit
⚪ Not started

Run Devin Review

Devin Review (Staging)

…urity:S5146)

Co-Authored-By: Joao Esteves <joao.esteves@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

SonarQube remediation — issue AZhSVLrd4wErqc9Ey1Y4, rule jssecurity:S5146 (BLOCKER)

What was vulnerable: routes/index.js:61, inside adminLoginSuccess(), called res.redirect(redirectPage) where redirectPage originates from req.body.redirectPage (admin login POST, echoed from req.query.redirectPage in the login view). Any user-controlled absolute URL was accepted, so the app could be used to bounce an authenticated victim to an attacker-controlled host (open redirect → phishing).

What changed: added isSafeRedirectPath() and gated the redirect on it. Only same-origin relative paths (starting with a single / and containing no backslash) are followed; anything else — absolute URLs (https://evil.[REDACTED SECRET]), protocol-relative URLs (//evil.[REDACTED SECRET]), backslash variants (/\evil.[REDACTED SECRET]), and non-string values — falls back to the default /admin.

Scope: one file, +9/−1. No refactoring, reformatting, or other vulnerability fixes; the SonarQube issue status was not modified.

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.

0 participants