PHPackages                             spaze/nonce-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. spaze/nonce-generator

ActiveLibrary[Security](/categories/security)

spaze/nonce-generator
=====================

Content Security Policy nonce generator

v4.0.3(5mo ago)74.5k↓50%1MITPHPPHP ^8.2CI passing

Since Nov 11Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/spaze/nonce-generator)[ Packagist](https://packagist.org/packages/spaze/nonce-generator)[ RSS](/packages/spaze-nonce-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (8)Versions (12)Used By (1)

Nonce Generator
===============

[](#nonce-generator)

[![PHP Tests](https://github.com/spaze/nonce-generator/workflows/PHP%20Tests/badge.svg)](https://github.com/spaze/nonce-generator/actions?query=workflow%3A%22PHP+Tests%22)

This generates random nonces for Content Security Policy *nonce* attributes. These nonces work with CSP3 [`strict-dynamic`](https://w3c.github.io/webappsec-csp/#strict-dynamic-usage) which aims to make Content Security Policy simpler to deploy for existing applications. This package is intended to be used with Nette Framework, [`spaze/csp-config`](https://github.com/spaze/csp-config) and [`spaze/sri-macros`](https://github.com/spaze/sri-macros).

Usage
-----

[](#usage)

This is a *plug and play* generator.

If installed, `\Spaze\ContentSecurityPolicy\Config::addDirective()` from `spaze/csp-config` will automatically add `nonce-...` attribute to configured directives, and [Latte](https://latte.nette.org/) macros `{script ...}` and `{stylesheet ...}` from `spaze/sri-macros` will add `nonce="..."` attribute to `script` and `style` attributes respectively. Also `n:nonce` [shortcut](https://doc.nette.org/en/http/configuration#toc-content-security-policy) will use the same generated value.

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org):

```
composer require spaze/nonce-generator

```

Add the extension to your configuration:

```
extensions:
	nonceGenerator: Spaze\NonceGenerator\Bridges\Nette\GeneratorExtension
```

Requirements
------------

[](#requirements)

- PHP 8.2 or newer
- Latte 3.0 or newer
- Nette Application 3.1 or newer
- Nette DI 3.0 or newer

API
---

[](#api)

```
createNonce(): Nonce

```

Generates and returns a `Nonce` object. Use `Nonce::getValue()` to get the generated nonce.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance70

Regular maintenance activity

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~329 days

Recently: every ~273 days

Total

11

Last Release

168d ago

Major Versions

v1.0.0 → v2.0.02017-12-19

v2.0.1 → v3.0.02019-04-14

v3.1.0 → v4.0.02023-05-04

PHP version history (5 changes)v2.0.0PHP ~7.0

v2.0.1PHP ~7.1

v3.0.2PHP ^7.1 || ^8.0

v3.1.0PHP ^8.0

v4.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6777bd445610e6e458e4d41bdefa3070d2ed4e068323362353b061b15e9ff81b?d=identicon)[spaze](/maintainers/spaze)

---

Top Contributors

[![spaze](https://avatars.githubusercontent.com/u/1966648?v=4)](https://github.com/spaze "spaze (50 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spaze-nonce-generator/health.svg)

```
[![Health](https://phpackages.com/badges/spaze-nonce-generator/health.svg)](https://phpackages.com/packages/spaze-nonce-generator)
```

###  Alternatives

[nextras/secured-links

Package secures Nette Framework signals against CSRF attack.

57668.1k11](/packages/nextras-secured-links)[tomaj/nette-api

Nette api

36261.8k4](/packages/tomaj-nette-api)[nepada/security-annotations

Security annotations for Nette presenters and components.

1113.3k1](/packages/nepada-security-annotations)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
