diff --git a/README.md b/README.md index 419da46..8c90049 100644 --- a/README.md +++ b/README.md @@ -41,18 +41,18 @@ git submodule add https://github.com/S1SYPHOS/kirby-sri.git site/plugins/kirby-s Activate the plugin with the following line in your `config.php`: ```text -c::set('sri-hash', true); +c::set('plugin.kirby-sri', true); ``` -Kirby's built-in helper functions `css()` and `js()` will now include an `integrity` attribute alongside the matching SRI hash. If you want to activate `sri-hash` only on specific domains, read about [multi-environment setups](https://getkirby.com/docs/developer-guide/configuration/options). +Kirby's built-in helper functions `css()` and `js()` will now include an `integrity` attribute alongside the matching SRI hash. If you want to activate `kirby-sri` only on specific domains, read about [multi-environment setups](https://getkirby.com/docs/developer-guide/configuration/options). ## Configuration Change `kirby-sri` options to suit your needs: | Option | Type | Default | Description | | --- | --- | --- | --- | -| `sri-hash.algorithm` | String | `sha512` | Defines the cryptographic [hash algorithm](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) (currently the allowed prefixes are `sha256`, `sha384` and `sha512`). | -| `sri-hash.use-credentials` | Boolean | `false` | Sets [crossorigin attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) to `use-credentials` instead of `anonymous`. | +| `plugin.kirby-sri.algorithm` | String | `sha512` | Defines the cryptographic [hash algorithm](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) (currently the allowed prefixes are `sha256`, `sha384` and `sha512`). | +| `plugin.kirby-sri.use-credentials` | Boolean | `false` | Sets [crossorigin attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) to `use-credentials` instead of `anonymous`. | ## Cache-busting / Fingerprinting [Same old, same old](https://www.keycdn.com/support/what-is-cache-busting/). If anyone comes up with a solution how subresource integrity and cache-busting / fingerprinting could be achieved by different plugins (as all of them modify Kirby's built-in helper functions `css()` and `js()`), feel free to open a PR! Otherwise, follow the next steps: diff --git a/core/css.php b/core/css.php index 7b87c82..190271c 100644 --- a/core/css.php +++ b/core/css.php @@ -53,7 +53,7 @@ public function tag($url, $media = null) { 'rel' => 'stylesheet', 'href' => url($url), 'integrity' => $cssIntegrity, // inject generated sri hash - 'crossorigin' => c::get('sri-hash.use-credentials') ? 'use-credentials' : 'anonymous' // set user-defined 'crossorigin' attribute + 'crossorigin' => c::get('plugin.kirby-sri.use-credentials') ? 'use-credentials' : 'anonymous' // set user-defined 'crossorigin' attribute ); if(is_array($media)) { diff --git a/core/js.php b/core/js.php index 83bb346..456ab35 100644 --- a/core/js.php +++ b/core/js.php @@ -52,7 +52,7 @@ public function tag($src, $async = false) { $attr = array( 'src' => url($src), 'integrity' => $jsIntegrity, // inject generated sri hash - 'crossorigin' => c::get('sri-hash.use-credentials') ? 'use-credentials' : 'anonymous' // set user-defined 'crossorigin' attribute + 'crossorigin' => c::get('plugin.kirby-sri.use-credentials') ? 'use-credentials' : 'anonymous' // set user-defined 'crossorigin' attribute ); if(is_array($async)) { diff --git a/kirby-sri.php b/kirby-sri.php index f76282c..2f78e20 100644 --- a/kirby-sri.php +++ b/kirby-sri.php @@ -1,16 +1,18 @@ + * @package Kirby CMS + * @author S1SYPHOS + * @link http://twobrain.io + * @version 0.4.0 */ -if(!c::get('sri-hash')) return; +if(!c::get('plugin.kirby-sri')) return; function sri_checksum($input) { - $algorithm = c::get('sri-hash.algorithm') ? c::get('sri-hash.algorithm') : 'sha512'; + $algorithm = c::get('plugin.kirby-sri.algorithm') ? c::get('plugin.kirby-sri.algorithm') : 'sha512'; $hash = hash($algorithm, $input, true); $hash_base64 = base64_encode($hash); diff --git a/package.json b/package.json index f1f3066..64d3ca4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "sri-hash", "description": "Kirby SRI Hash & Cache-bust Plugin", "author": "S1SYPHOS ", - "version": "0.3.0", + "version": "0.4.0", "type": "kirby-plugin", "license": "MIT" }