This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($sce): Consider document base URL for 'self' URL policy. #15145
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
525067d
fix($sce): Consider document base URL when implementing 'self' URL po…
adob 08432a0
improve test
adob 382c414
track changes to base URL and other refactorings
adob 49b8e0d
fix tests
adob abd7dd7
make urlIsSameOriginAsBaseUrl() run on Linux
adob 38ddb97
review feedback
adob 48a0123
remove redundant url parsing calls
adob d2b2d37
Add unit test
adob 9db4eaf
adding unit test to sceSpec.js
adob 01fc4f1
lint fixups
adob ebf45a4
fix test for IE9
adob 79ab27a
fix lint issue
adob f6f5d9e
fix typo and refactor tests as per code review
adob 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
<!DOCTYPE html> | ||
<html ng-app="test"> | ||
<head> | ||
<base href="http://www.example.com/"> | ||
<script src="http://localhost:8000/build/angular.js"></script> | ||
<script src="http://localhost:8000/e2e/fixtures/base-tag/script.js"></script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains hidden or 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,14 @@ | ||
'use strict'; | ||
|
||
angular. | ||
module('test', []). | ||
run(function($sce) { | ||
window.isTrustedUrl = function(url) { | ||
try { | ||
$sce.getTrustedResourceUrl(url); | ||
} catch (e) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
}); |
This file contains hidden or 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,35 @@ | ||
'use strict'; | ||
|
||
describe('SCE URL policy when base tags are present', function() { | ||
function checkUrl(url, allowed) { | ||
var urlIsTrusted = browser.executeScript('return isTrustedUrl(arguments[0])', url); | ||
expect(urlIsTrusted).toBe(allowed); | ||
} | ||
|
||
beforeAll(function() { | ||
loadFixture('base-tag'); | ||
}); | ||
|
||
it('allows the page URL (location.href)', function() { | ||
checkUrl(browser.getLocationAbsUrl(), true); | ||
}); | ||
|
||
it('blocks off-origin URLs', function() { | ||
checkUrl('http://evil.com', false); | ||
}); | ||
|
||
it('allows relative URLs ("/relative")', function() { | ||
checkUrl('/relative', true); | ||
}); | ||
|
||
it('allows absolute URLs from the base origin', function() { | ||
checkUrl('http://www.example.com/path/to/file.html', true); | ||
}); | ||
|
||
it('tracks changes to the base URL', function() { | ||
browser.executeScript( | ||
'document.getElementsByTagName("base")[0].href = "http://xxx.example.com/";'); | ||
checkUrl('http://xxx.example.com/path/to/file.html', true); | ||
checkUrl('http://www.example.com/path/to/file.html', false); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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
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.
Nit: I would rather not duplicate the code. Maybe have a base function that
urlIsSameOrigin
/urlIsSameOriginAsBase
can delegate two (and pass theoriginUrl
/baseUrl
as parameters).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.
Done.