Repository navigation
Count calls of device interfaces, not mentions, in DPP-SEC-021 - #38
Merged
Merged
Conversation
The html check with device_features reads inline scripts, event handler attributes, javascript: URLs and the page's own scripts as JavaScript tokens (JsTokens) and looks for uses of device functions (DeviceUses): calls of device methods and interfaces, permission requests, listeners for device events. Names in comments and strings, feature detection and hooks without a call, such as zone.js installs on navigator.geolocation in the polyfills of Angular applications, no longer fail the criterion. A reference after which a use may follow that only running the script would show gives a warning if there is no use. A script that cannot be read as JavaScript is searched for the names as before, with a warning instead of a failure. A script cut after 2 MB is read up to the cut. Test vectors for the polyfill pattern, a real call next to it, feature detection, names in comments and strings and each kind of warning; unit tests for JsTokens and DeviceUses. The image is built with dpp-criteria main, where DPP-SEC-021 is version 2.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes
DPP-SEC-021 ("HTML view uses no device functions") failed for HTML views built with Angular: zone.js in their polyfills tests whether
navigator.geolocationexists and wrapsgetCurrentPositionandwatchPosition, without calling them. The check found.geolocationand reported a use of the location.device_features: forbiddennow follows the definition in CRITERIA-FORMAT.md of dpp-criteria (DPP-SEC-021 version 2):JsTokenssplits a script into tokens, as far as needed to tell code from comments, string, template and regular expression literals. Text that cannot be read as JavaScript raises an error; a script cut after 2 MB may end inside a token.DeviceUseslooks in the tokens for uses: calls of device methods and of methods of device interfaces, readingnavigator.connection, permission requests,newwith device classes, listeners for device events,transport: ['sms']. Testing whether an interface exists, replacing its methods and passing it to a function together with the names of its members (the zone.js pattern) are not a use.addEventListeneroron. Without a use, doubts give awarning("no use of functions of the reader's device was found, but the HTML view may use them: …").HtmlCheckreports uses as before (one violation message) and, without a use, the doubts as a warning. Findings name the call instead of the name found, e.g.location (.getCurrentPosition() in inline script 1).The markup part is unchanged. Scripts without any of the names are not tokenized, so pages without device interfaces cost no more than before.
Effect
Of the example passports of the listed services, one HTML view fails DPP-SEC-021 today only because of zone.js; it passes with this change. All other results stay the same. DPP-SEC-021 is
proposedand does not count in "N of M".Tests
test/fixtures/files/html/DPP-SEC-021/: new valid ones (a polyfill that hooks into the location interface, feature detection, names in comments and strings), a new invalid one (the same polyfill next to a real call under another name) and a newwarning/directory (method read without a call, interface stored, event name passed to a function, script that cannot be read). With the previous check the new valid vectors fail.test/services/js_tokens_test.rbandtest/services/device_uses_test.rb.JsTokenswas compared token by token with a standard JavaScript parser on 78 scripts (about 5.8 million tokens: zone.js 0.8 to 0.15, Angular, React, Vue, jQuery, TypeScript, Leaflet, OpenLayers, MapLibre, Mapbox GL, highlight.js and others): no difference. Cut at random places, the tokens up to the cut stay the same.