Skip to content

Commit a64d548

Browse files
authored
Re-encode the URI for the SAML redirect link (#3406)
On the SAML login page, when we pull out the redirect_uri from the url for the redirect link, it's decoded automatically. When the URI is just a path, like `/system`, the decoded form on Nexus' end is still a valid URI. But if there's a sufficiently complex query, with things like whitespace (or, say, OxQL comparison operators), Nexus will rightly refuse to parse that after decoding. Simple enough; just re-encode it!
1 parent df32a01 commit a64d548

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎app/pages/LoginPageSaml.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function LoginPageSaml() {
1818
const { silo, provider } = useIdpSelector()
1919

2020
const redirect_uri = searchParams.get('redirect_uri')?.trim()
21-
const query = redirect_uri ? `?redirect_uri=${redirect_uri}` : ''
21+
const query = redirect_uri ? `?redirect_uri=${encodeURIComponent(redirect_uri)}` : ''
2222

2323
return (
2424
<>

‎test/e2e/login-saml.e2e.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ test.describe('SAML login', () => {
2424
const button = page.getByRole('link', { name: 'Sign in with mock-idp' })
2525
await expect(button).toHaveAttribute(
2626
'href',
27-
'/login/default-silo/saml/mock-idp/redirect?redirect_uri=/projects/mock-project/instances'
27+
'/login/default-silo/saml/mock-idp/redirect?redirect_uri=%2Fprojects%2Fmock-project%2Finstances'
2828
)
2929
})
30+
31+
test('redirect_uri with a query string stays encoded', async ({ page }) => {
32+
const target = '/system/metrics?query=get vm:cpu | filter state == "run"'
33+
await page.goto(
34+
`/login/default-silo/saml/mock-idp?redirect_uri=${encodeURIComponent(target)}`
35+
)
36+
const button = page.getByRole('link', { name: 'Sign in with mock-idp' })
37+
const href = new URL((await button.getAttribute('href'))!, page.url()) // link always has href
38+
expect(href.pathname).toBe('/login/default-silo/saml/mock-idp/redirect')
39+
expect(href.searchParams.get('redirect_uri')).toBe(target)
40+
expect(href.search).not.toMatch(/[ |"]/)
41+
})
3042
})

0 commit comments

Comments
 (0)