Closed Bug 621106 Opened 15 years ago Closed 15 years ago

Add-On Validator check for changes to prototype of native JavaScript objects has false positives.

Categories

(addons.mozilla.org Graveyard :: Developer Pages, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: CodeMachine, Assigned: basta)

Details

The check for changes to the prototype of native JavaScript objects also finds other prototype changes: chrome/internote.jar/content/internote-utils.js (27) : Matched Pattern: "/(Object|Array|String|Number|Boolean|Date)\.prototype/" internoteSharedGlobal_e3631030_7c02_11da_a72b_0800200c9a66.BaseObject.prototype = ... I suggest that the pattern start with a non-identifier character to avoid.
Matt, can you check if the new validator also does this? Pattern could change to something more specific, perhaps with a word boundary: /\b(Object|Array|String|Number|Boolean|Date)\.prototype/
Assignee: nobody → mbasta
What is "the new validator"?
(In reply to comment #2) > What is "the new validator"? https://github.com/mattbasta/amo-validator
The new validator doesn't use pattern matching to detect base object prototype changes, it blacklists write access to the base object types' prototype attribute during its analysis. If there's something I can test against, I'd be happy to. In the error provided above, the validator would not mark that as a false positive. In order to throw an error, the validator would need to detect access to the base objects, then find a member expression which accesses the prototype (or contructor) object. I believe it also prevents developers from assigning values to other properties of the base types (i.e.: Number.foo = "asdf").
Just as a reference... There is a unit test which detects modification to the base objects from bug 538016: https://github.com/mattbasta/amo-validator/blob/master/tests/test_bug_538016.py https://github.com/mattbasta/amo-validator/blob/master/tests/resources/bug_538016.js Also, the validator specifically marks the prototypes for the base objects as dangerous: https://github.com/mattbasta/amo-validator/blob/master/validator/testcases/javascript/predefinedentities.py
I just pushed some improvements to the javascript tests, along with some unit tests that specifically test for access surrounding base object prototypes: https://github.com/mattbasta/amo-validator/commit/f409a873f512b1dd9de42e6926a9b31f1235e1d1 https://github.com/mattbasta/amo-validator/commit/66980c173a58d1c9de479b09836eb92dd89d6d40 Also, it should be noted that in some cases it's illegal to simply access the base objects (namely Function) because it poses other security vulnerabilities.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.