-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #42 Add support for integrity hashes (Lyrkan)
This PR was squashed before being merged into the master branch (closes #42). Discussion ---------- Add support for integrity hashes This PR allows to automatically add `integrity` attributes on `<script>` and `<link>` tags based on the content of the `entrypoints.json` file (related to the following PR on Encore: symfony/webpack-encore#522). It requires the following configuration: ```js // webpack.config.js // Enable it for all builds with the // default hash algorithm (sha384) Encore.enableIntegrityHashes(); // Or enable it only in production // with a custom hash algorithm Encore.enableIntegrityHashes( Encore.isProduction(), 'sha384' ); // Or with multiple hash algorithms Encore.enableIntegrityHashes( Encore.isProduction(), ['sha384','sha512'] ); ``` Then, calling `yarn encore` then generates an entrypoints.json that contains hashes for all the files it references: ```js { "entrypoints": { // (...) }, "integrity": { "/build/runtime.fa8f03f5.js": "sha384-5WSgDNxkAY6j6/bzAcp3v//+PCXLgXCU3u5QgRXWiRfMnN4Ic/a/EF6HJnbRXik8", "/build/0.b70b772e.js": "sha384-FA3+8ecenjmV1Y751s0fKxGBNtyLBA8hDY4sqFoqvsCPOamLlA5ckhRBttBg1esp", // (...) } } ``` And these hashes are automatically added when calling `encore_entry_script_tags` and `encore_entry_link_tags`: ```html <html lang="en"> <head> <!-- ... --> <link rel="stylesheet" href="/build/css/app.2235bc2d.css" integrity="sha384-Jmd35HF93DFCXjisVeMi6U3lniH/mOdAF6wLtOMqhYMh2ZiBRUdtF7jXB55IAKfm"> <!-- ... --> </head> <body id="homepage"> <!-- ... --> <script src="/build/runtime.fa8f03f5.js" integrity="sha384-5WSgDNxkAY6j6/bzAcp3v//+PCXLgXCU3u5QgRXWiRfMnN4Ic/a/EF6HJnbRXik8"></script> <script src="/build/0.b70b772e.js" integrity="sha384-FA3+8ecenjmV1Y751s0fKxGBNtyLBA8hDY4sqFoqvsCPOamLlA5ckhRBttBg1esp"></script> <!-- ... --> </body> </html> ``` An example using Symfony Demo can be found here: Lyrkan/symfony-demo@91a06cd Commits ------- 84c41ed Add support for integrity hashes
- Loading branch information
Showing
7 changed files
with
156 additions
and
10 deletions.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony WebpackEncoreBundle package. | ||
* (c) Fabien Potencier <[email protected]> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\WebpackEncoreBundle\Asset; | ||
|
||
interface IntegrityDataProviderInterface | ||
{ | ||
/** | ||
* Returns a map of integrity hashes indexed by asset paths. | ||
* | ||
* If multiples hashes are defined for a given asset they must | ||
* be separated by a space. | ||
* | ||
* For instance: | ||
* [ | ||
* 'path/to/file1.js' => 'sha384-Q86c+opr0lBUPWN28BLJFqmLhho+9ZcJpXHorQvX6mYDWJ24RQcdDarXFQYN8HLc', | ||
* 'path/to/styles.css' => 'sha384-ymG7OyjISWrOpH9jsGvajKMDEOP/mKJq8bHC0XdjQA6P8sg2nu+2RLQxcNNwE/3J', | ||
* ] | ||
* | ||
* @return string[] | ||
*/ | ||
public function getIntegrityData(): array; | ||
} |
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
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
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