Skip to content

Commit

Permalink
✨ added default frontend nonce at site-object
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Feb 8, 2020
1 parent a2e74df commit c06bb61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bnomei/kirby3-security-headers",
"type": "kirby-plugin",
"version": "2.2.0",
"version": "2.2.1",
"license": "MIT",
"description": "Kirby 3 Plugin for easier Security Headers setup",
"authors": [
Expand Down
14 changes: 14 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@
);
},
],
'siteMethods' => [
'nonce' => function (): string {
return \Bnomei\SecurityHeaders::singleton()->getNonce(site()->url());
},
'nonceAttr' => function (): string {
return implode(
[
'nonce="',
\Bnomei\SecurityHeaders::singleton()->getNonce(site()->url()),
'"',
]
);
},
],
]);
12 changes: 9 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,21 @@ return [
## Panel and Frontend Nonces

This plugin automatically registers Kirbys nonce for the panel. For convenience it also provides you with a single *frontend nonce* to use as attribute in `<link>`, `<style>` and `<script>` elements.
This plugin automatically registers Kirbys nonce for the panel. For convenience it also provides you with a single *frontend nonce* to use as attribute in `<link>`, `<style>` and `<script>` elements. You can retrieve the nonce with `site()->nonce()` and the full attribute with `site()->nonceAttr()`.

```php
<script <?= $page->nonceAttr(site()->url()) ?>>
<?php ?>

<script nonce="<?= site()->nonce() ?>">
// ...
</script>

<style <?= site()->nonceAttr() ?>>
</style>
```

> TIP: The [srcset plugin](https://github.com/bnomei/kirby3-srcset/) uses that frontend nonce as well.
> TIP: The [srcset plugin](https://github.com/bnomei/kirby3-srcset/) uses that *frontend nonce* as well.
## Settings

Expand Down

0 comments on commit c06bb61

Please sign in to comment.