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($parse): block assigning to fields of a constructor #12860
Closed
Closed
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -2703,6 +2703,32 @@ describe('parser', function() { | |
''); | ||
}).toThrow(); | ||
}); | ||
|
||
it('should prevent assigning in the context of a constructor', function() { | ||
expect(function() { | ||
scope.$eval("''.constructor.join"); | ||
}).not.toThrow(); | ||
expect(function() { | ||
scope.$eval("''.constructor.join = ''.constructor.join"); | ||
}).toThrow(); | ||
expect(function() { | ||
scope.$eval("''.constructor[0] = ''"); | ||
}).toThrow(); | ||
expect(function() { | ||
scope.$eval("(0).constructor[0] = ''"); | ||
}).toThrow(); | ||
expect(function() { | ||
scope.$eval("{}.constructor[0] = ''"); | ||
}).toThrow(); | ||
// foo.constructor is the object constructor. | ||
expect(function() { | ||
scope.$eval("foo.constructor[0] = ''", {foo: {}}); | ||
}).toThrow(); | ||
// foo.constructor is not a constructor. | ||
expect(function() { | ||
scope.$eval("foo.constructor[0] = ''", {foo: {constructor: ''}}); | ||
}).not.toThrow(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For good measure we could also test assigning to a variable that has been set to a constructor: expect(function() {
scope.$eval("foo = {}.constructor; foo.join = ''");
}).toThrow(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}); | ||
|
||
it('should call the function from the received instance and not from a new one', function() { | ||
|
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.
So we only care about built-in constructors?
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.
we care the ones an expression can invoke and can be used to break the sandbox... the only other I can think about is
Scope
, but I really have no idea if it can be maliciously used. The alternative would be blocking to any property namedconstructor
, but it might be just too much and there might be valid uses.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.
So I guess we can't protect against developers putting stuff on the scope via a controller, such as the
window
object, for instance?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.
there are other protections in place that prevent any form of access to several objects. Eg. DOM nodes and
window