jonathanKingston/ember-cli-sri(新しいタブで開きます)
主要言語: JavaScript
Generation of SRI hashes for ember
- star 数
- 48
- watcher 数
- 2
- fork 数
- 15
- issue 数
- 11
- 最終更新
- 2016/10/18
主要言語: JavaScript
Generation of SRI hashes for ember
This plugin is used to generate Subresource Integrity (SRI) hashes for ember applications. Subresource integrity is a security concept used to check JavaScript and stylesheets are loaded with the correct content when using a CDN.
The reason to add this to your application is to protect against poisoned CDNs breaking JavaScript or CSS subresources.
ember install ember-cli-sriIn Brocfile.js or ember-cli-build.js:
var app = new EmberApp({ });
Or:
var app = new EmberApp({ SRI: { crossorigin: 'anonymous' }, fingerprint: { prepend: 'https://subdomain.cloudfront.net/' } });
SRI.crossoriginOr:
var app = new EmberApp({ origin: 'https://subdomain.cloudfront.net/', fingerprint: { prepend: 'https://subdomain.cloudfront.net/' } });
origin attributeuse-credentialsanonymous<script src="https://example.com/thing-5e1978f9cfa158d9841d7b6d8a4e5c57.js" integrity="sha256-oFeuE/P+XJMjkMS5pAPudQOMGJQ323nQt+DQ+9zbdAg= sha512-+EXjzt0I7g6BjvqqjkkboGyRlFSfIuyzY2SQ43HQKZBrHsjmRzEdjSHhiDzVs30nXL9H0tKw6WbMPc6RfzUumQ==" crossorigin="anonymous" /></script> <script src="https://example.com/thing-5e1978f9cfa158d9841d7b6d8a4e5c57.js" crossorigin="use-credentials" integrity="sha256-oFeuE/P+XJMjkMS5pAPudQOMGJQ323nQt+DQ+9zbdAg= sha512-+EXjzt0I7g6BjvqqjkkboGyRlFSfIuyzY2SQ43HQKZBrHsjmRzEdjSHhiDzVs30nXL9H0tKw6WbMPc6RfzUumQ=="/></script> <script src="unicode-chars.js" integrity="sha256-TH5eRuwfOSKZE0EKVF4WZ6gVQ/zUch4CZE2knqpS4MU= sha512-eANuTl8NOQEa4/zm44zxX6g7ffwf6NXftA2sv4ZiQURnJsfJkUnYP8XpN2XVVZee4SjB32i28WM6trs9HVgQmA=="/></script>
This addon should fail safely at all times so resources matching https? need:
fingerprint.prependSRI.crossorigin attribute must be set or a matching origin to fingerprint.prependIf the config is not set correctly it should result in just a lack of SRI protection, which is better than a broken website.
Please file bugs if you find a case when the config doesn't 'fail safe', is not clear or results in a broken page.
If your Ember application is NOT being loaded on the same origin as in fingerprint.prepend:
fingerprint.prepend domain will need to be serving CORS HeadersIf your Ember application is being loaded on the same origin as in fingerprint.prepend:
In code that uses SRI, you MUST NOT tamper with the built output JavaScript files as code will not load.
When the request doesn't match Same Origin Policy the crossorigin attribute MUST be present for the integrity of the file to be checked. With an integrity set on an external origin and a missing crossorigin the browser will choose to 'fail-open' which means it will load the resource as if the integrity attribute was not set.
Values:
crossorigin attribute, this will be changed to 'fail-close' which is simpler to debug.There was an encoding issue based on certain characters when using Chrome, the fix for which landed in Chrome 46. This check fails if there is any non ASCII characters. On failure the file won't have an integrity attribute added. Currently, it defaults to false (i.e. this check is disabled). You can reenable it if you wish to remain compatible with versions of Chrome < 46.
If you are fingerprinting your assets and/or prepending a URL (e.g. to your static web server or CDN), you will likely want to disable this check. Otherwise, if your assets include other assets, they will fail the check and the file won't have an integrity attribute added. Currently, it defaults to false (i.e. this check is disabled). You can reenable it for a little extra confidence that the correct files are being hashed, but only if you are not fingerprinting or prepending your assets and have no plans to in the future.
Notes:
npm test