Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Released v0.4.0 🍾
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS committed Nov 6, 2017
1 parent 9c8c89b commit 6acc124
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion core/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion core/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 7 additions & 5 deletions kirby-sri.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?php

/**
* Adding SRI Hash to css & js files and cache-busting them
* Kirby SRI - Adding SRI Hash to css & js files and cache-busting them
*
* @version 0.3.0
* @author S1SYPHOS <[email protected]>
* @package Kirby CMS
* @author S1SYPHOS <[email protected]>
* @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);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sri-hash",
"description": "Kirby SRI Hash & Cache-bust Plugin",
"author": "S1SYPHOS <[email protected]>",
"version": "0.3.0",
"version": "0.4.0",
"type": "kirby-plugin",
"license": "MIT"
}

0 comments on commit 6acc124

Please sign in to comment.