Skip to content

security(csp): version-safe inline-script nonce wrapper + strengthen PO/MO instructions - #67

Merged
TheWitness merged 3 commits into
developfrom
feature/csp-nonce-inline-js
Sep 28, 2026
Merged

TheWitness merged 3 commits into
developfrom
feature/csp-nonce-inline-js

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Part of the fleet-wide CSP-nonce rollout (mirrors the pilot Cacti/plugin_mactrack#374).

  1. Version-safe CSP nonce on inline JavaScript. Adds a wrapper
    plugin_<name>_csp_nonce() and applies it to every inline <script> block, so
    pages stay compatible with Cacti's Content-Security-Policy nonce enforcement.
  2. Strengthened i18n instruction in .github/copilot-instructions.md — the
    .po/.mo files are never committed (Weblate owns them); only cacti.pot.

Wrapper (cross-version safe)

function plugin_<name>_csp_nonce(): string {
	if (class_exists('CactiSecureHeaders')) {
		return CactiSecureHeaders::getNonceAttribute();
	}

	return '';
}

Emits the per-request nonce="..." on Cacti releases that ship CactiSecureHeaders
(present on both develop and 1.2.x), and '' on older releases — so the tag
stays valid either way. The wrapper lives in the plugin's functions library where one
exists, otherwise in setup.php (loaded on every Cacti page by the plugin loader).

Also

  • tests/Unit/CspNonceTest.php covers the empty-string fallback, the string
    return type, and delegation to CactiSecureHeaders.
  • Where the plugin emits its own external <script src> / CSS <link>, those go
    through Cacti's get_md5_include_js() / get_md5_include_css() helpers (automatic
    nonce + md5 cache-buster).
  • locales/po/cacti.pot regenerated for shifted source line references; the
    per-language .po/.mo catalogs are intentionally not committed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Resolve the CSP event-handler issue and correct the fallback test setup.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Adds version-safe CSP nonce support for inline JavaScript and strengthens translation-catalog guidance.

Changes:

  • Adds and applies plugin_maint_csp_nonce().
  • Adds CSP nonce tests.
  • Updates i18n instructions, POT references, and changelog.
File Summary
tests/​Unit/​CspNonceTest.php Adds nonce helper tests; fallback testing requires correction for CI class availability.
setup.php Adds the nonce helper and updates inline JavaScript; inline event handlers remain unresolved.
maint.php Adds nonce attributes to inline scripts.
locales/​po/​cacti.pot Updates generated source references.
CHANGELOG.md Documents CSP nonce support.
.github/​copilot-instructions.md Clarifies PO/MO ownership rules.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/Unit/CspNonceTest.php Resolved
@TheWitness
TheWitness merged commit 72743ae into develop Sep 28, 2026
3 checks passed
@TheWitness
TheWitness deleted the feature/csp-nonce-inline-js branch September 28, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants