-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Support deep links inside of RelayState
for SAML IdP initiated login.
#69401
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85f2076
Support deep links inside of `RelayState` during IdP initiated login.
azasypkin d6f9213
Merge branch 'master' into issue-xxx-relay-state
azasypkin 0966b62
Review#1: handle review feedback.
azasypkin 2ac64a2
Merge branch 'master' into issue-xxx-relay-state
azasypkin 20b1830
Use global `URL` instead and rely on CoreJS polyfill.
azasypkin ac705c9
Fix Jest URL polyfill.
azasypkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { isInternalURL } from './is_internal_url'; | ||
|
||
describe('isInternalURL', () => { | ||
describe('with basePath defined', () => { | ||
const basePath = '/iqf'; | ||
|
||
it('should return `true `if URL includes hash fragment', () => { | ||
const href = `${basePath}/app/kibana#/discover/New-Saved-Search`; | ||
expect(isInternalURL(href, basePath)).toBe(true); | ||
}); | ||
|
||
it('should return `false` if URL includes a protocol/hostname', () => { | ||
const href = `https://example.com${basePath}/app/kibana`; | ||
expect(isInternalURL(href, basePath)).toBe(false); | ||
}); | ||
|
||
it('should return `false` if URL includes a port', () => { | ||
const href = `http://localhost:5601${basePath}/app/kibana`; | ||
expect(isInternalURL(href, basePath)).toBe(false); | ||
}); | ||
|
||
it('should return `false` if URL does not specify protocol', () => { | ||
const hrefWithTwoSlashes = `/${basePath}/app/kibana`; | ||
expect(isInternalURL(hrefWithTwoSlashes)).toBe(false); | ||
|
||
const hrefWithThreeSlashes = `//${basePath}/app/kibana`; | ||
expect(isInternalURL(hrefWithThreeSlashes)).toBe(false); | ||
}); | ||
|
||
it('should return `true` if URL starts with a basepath', () => { | ||
for (const href of [basePath, `${basePath}/`, `${basePath}/login`, `${basePath}/login/`]) { | ||
expect(isInternalURL(href, basePath)).toBe(true); | ||
} | ||
}); | ||
|
||
it('should return `false` if URL does not start with basePath', () => { | ||
for (const href of [ | ||
'/notbasepath/app/kibana', | ||
`${basePath}_/login`, | ||
basePath.slice(1), | ||
`${basePath.slice(1)}/app/kibana`, | ||
]) { | ||
expect(isInternalURL(href, basePath)).toBe(false); | ||
} | ||
}); | ||
|
||
it('should return `true` if relative path does not escape base path', () => { | ||
const href = `${basePath}/app/kibana/../../management`; | ||
expect(isInternalURL(href, basePath)).toBe(true); | ||
}); | ||
|
||
it('should return `false` if relative path escapes base path', () => { | ||
const href = `${basePath}/app/kibana/../../../management`; | ||
expect(isInternalURL(href, basePath)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('without basePath defined', () => { | ||
it('should return `true `if URL includes hash fragment', () => { | ||
const href = '/app/kibana#/discover/New-Saved-Search'; | ||
expect(isInternalURL(href)).toBe(true); | ||
}); | ||
|
||
it('should return `false` if URL includes a protocol/hostname', () => { | ||
const href = 'https://example.com/app/kibana'; | ||
expect(isInternalURL(href)).toBe(false); | ||
}); | ||
|
||
it('should return `false` if URL includes a port', () => { | ||
const href = 'http://localhost:5601/app/kibana'; | ||
expect(isInternalURL(href)).toBe(false); | ||
}); | ||
|
||
it('should return `false` if URL does not specify protocol', () => { | ||
const hrefWithTwoSlashes = `//app/kibana`; | ||
expect(isInternalURL(hrefWithTwoSlashes)).toBe(false); | ||
|
||
const hrefWithThreeSlashes = `///app/kibana`; | ||
expect(isInternalURL(hrefWithThreeSlashes)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { parse } from 'url'; | ||
|
||
export function isInternalURL(url: string, basePath = '') { | ||
const { protocol, hostname, port, pathname } = parse( | ||
url, | ||
false /* parseQueryString */, | ||
true /* slashesDenoteHost */ | ||
); | ||
|
||
// We should explicitly compare `protocol`, `port` and `hostname` to null to make sure these are not | ||
// detected in the URL at all. For example `hostname` can be empty string for Node URL parser, but | ||
// browser (because of various bwc reasons) processes URL differently (e.g. `///abc.com` - for browser | ||
// hostname is `abc.com`, but for Node hostname is an empty string i.e. everything between schema (`//`) | ||
// and the first slash that belongs to path. | ||
if (protocol !== null || hostname !== null || port !== null) { | ||
return false; | ||
} | ||
|
||
if (basePath) { | ||
// Now we need to normalize URL to make sure any relative path segments (`..`) cannot escape expected | ||
// base path. We can rely on `URL` with a localhost to automatically "normalize" the URL. | ||
const normalizedPathname = new URL(String(pathname), 'https://localhost').pathname; | ||
return ( | ||
// Normalized pathname can add a leading slash, but we should also make sure it's included in | ||
// the original URL too | ||
pathname?.startsWith('/') && | ||
(normalizedPathname === basePath || normalizedPathname.startsWith(`${basePath}/`)) | ||
); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: at some point we may want to migrate from legacy
url.parse
API to this WHATWG URL API completely, but I couldn't find a reasonable way to figure out whether URL is relative or absolute just using this new API. The only option I can think of is something like this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to get this to work locally. When trying to login with a base path, I'm presented with an error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, nice find! That's because
URL
got intoimport
somehow. It's should be a global instead. But now I'm worried it may not be supported by IE11 - checking..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've pushed the fix (moved
URL
out ofimport
as it should be). I see we use polyfill from CoreJS for the URL so it should work in IE 11. I'll manually pick that fix to 7.8 to check, cause master doesn't work in IE anymore 😢There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked on 7.8 - the URL polyfill works fine in IE 11 :phew: