-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expands the secure_rel utility to handle elastic domains (#1565)
* Expands the getSecureRelForTarget utility to let referrer's pass-through to elastic.co domains.
- Loading branch information
1 parent
98e5cbf
commit 99b52fd
Showing
11 changed files
with
207 additions
and
42 deletions.
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
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
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
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
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,33 @@ | ||
import { isDomainSecure } from './url'; | ||
|
||
describe(`url`, () => { | ||
describe(`#isDomainSecure`, () => { | ||
it(`returns true for secure domains`, () => { | ||
expect(isDomainSecure('https://elastic.co')).toEqual(true); | ||
expect(isDomainSecure('https://elastic.co?foo=bar')).toEqual(true); | ||
expect(isDomainSecure('https://elastic.co/')).toEqual(true); | ||
expect(isDomainSecure('https://www.elastic.co')).toEqual(true); | ||
expect(isDomainSecure('https://docs.elastic.co')).toEqual(true); | ||
expect(isDomainSecure('https://stats.elastic.co')).toEqual(true); | ||
expect(isDomainSecure('https://lots.of.kids.elastic.co')).toEqual(true); | ||
expect( | ||
isDomainSecure('https://elastic.co/cool/url/with?lots=of¶ms') | ||
).toEqual(true); | ||
}); | ||
|
||
it(`returns false for unsecure domains`, () => { | ||
expect(isDomainSecure('https://wwwelastic.co')).toEqual(false); | ||
expect(isDomainSecure('https://www.zelastic.co')).toEqual(false); | ||
expect(isDomainSecure('https://*elastic.co')).toEqual(false); | ||
expect(isDomainSecure('http://elastic.com')).toEqual(false); | ||
expect(isDomainSecure('https://elastic.co.now')).toEqual(false); | ||
expect(isDomainSecure('elastic.co')).toEqual(false); | ||
expect(isDomainSecure('smb://www.elastic.co')).toEqual(false); | ||
expect( | ||
isDomainSecure( | ||
'https://wwwelastic.co/cool/url/with?lots=of¶ms/https://elastic.co' | ||
) | ||
).toEqual(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,16 @@ | ||
const isElasticDomain = /(https?:\/\/(.+?\.)?elastic\.co((\/|\?)[A-Za-z0-9\-\._~:\/\?#\[\]@!$&'\(\)\*\+,;\=]*)?)/g; | ||
|
||
// In order for the domain to be secure the regex | ||
// has to match _and_ the lengths of the match must | ||
// be _exact_ since URL's can have other URL's as | ||
// path or query params! | ||
export const isDomainSecure = (url: string = '') => { | ||
const matches = url.match(isElasticDomain); | ||
|
||
if (!matches) { | ||
return false; | ||
} | ||
const [match] = matches; | ||
|
||
return match.length === url.length; | ||
}; |