Skip to content

Add opt-in integrity pinning for analytics scripts - #61

Open
jdevalk wants to merge 9 commits into
simpleanalytics:mainfrom
jdevalk:codex/script-pinning
Open

jdevalk wants to merge 9 commits into
simpleanalytics:mainfrom
jdevalk:codex/script-pinning

Conversation

@jdevalk

@jdevalk jdevalk commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The plugin currently executes mutable third-party analytics scripts. This adds an opt-in Pin analytics scripts setting so browsers reject unexpected script changes instead of executing them.

  • Load the versioned v12 analytics script with a fixed SHA-384 integrity hash and anonymous CORS.
  • Bundle a reviewed, commit-pinned automated-events script with its MIT license and fixed integrity hash.
  • Require separate custom-domain hash approval by a user with unfiltered_html; bind approval to the site, domain, version, and hash. Domain changes clear approval, and missing or expired approval pauses tracking with a visible notice.
  • Keep pinning disabled by default. Never refresh hashes automatically or fall back to unpinned scripts. Document cache clearing, script-optimization exclusions, and release maintenance.

Dependency: depends on #58 for the existing custom-domain authorization controls. This branch includes that prerequisite commit; merge #58 first, then rebase this PR to leave only the pinning change. The branch also includes the latest main-branch fix from #60.

Validation: all 31 local Playwright/WordPress regression tests pass after rebasing onto current main, including rejection of altered main and bundled scripts, automated-event collection, custom-domain changes, invalid hashes, and permission checks. PHP/JavaScript syntax and whitespace checks pass. The official CDN script matches its published SHA-384 hash and serves CORS headers; custom-domain browser responses were mocked, so actual domain availability and CORS still require verification before enabling pinning there.

Update

Changes pushed on top of this PR, after merging the updated #58:

  • Every pinned script is bundled. resources/js/pinned/v12/ holds dist/v12/app.js, dist/v12/custom/app.js and dist/v12/auto-events.js from the scripts v12 release, unmodified, with fixed hashes. The automated-events copy came from an unreleased scripts commit. Pinned scripts now follow release versions, and their directory is built from VERSION, so v13 means three new files and three new hashes.
  • Custom domains need no hash approval. The custom-domain build sends data to the domain it is served from. The plugin fills in the saved domain, as the custom-domain server does, and saves the script in wp-content/uploads/simpleanalytics/. The hash field, its approval and the paused state are removed. If uploads isn't writable, visitors get the bundled default script and administrators see a warning. Uninstalling removes the written scripts.
  • Links added after load. The v12 automated-events script only tracks links present when the page loads. Tracking links added later arrives with v13.

The dependency on #58 still applies.

Validation: all 32 browser and WordPress regression tests pass locally on WordPress 7.1.4 with PHP 8.5, plus the regression scripts on multisite. They cover altered bundled and written scripts, data going to the custom domain, and event collection. In a browser against the live CDN, the bundled v12 scripts send pageviews and events.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: ed815bfb-2d72-4a5a-a06c-21a7e651113c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

… optional

Custom domains saved before this release, set with WP-CLI, or saved before a
salt rotation now keep loading scripts. Changing the domain still requires
unfiltered_html, which is the check that stops site administrators on
multisite from choosing a script origin, so the approval hash is removed.
Pasted URLs are reduced to their hostname, and a rejected change or an
unusable saved value is explained beside the field, where the settings page
shows it.

Network administrators are excluded only when "Network administrator (Super
Admin)" is selected among the roles, so existing sites keep collecting their
visits. With no roles selected, every logged-in user stays excluded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the custom-domain, network administrator and release schedule
changes. Custom-domain changes still clear the script approval, and the
integrity field's errors now use the inline messages every input shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pinned main script is the v12 release, but the bundled events script was
taken from an unreleased scripts commit. Bundle src/auto-events.js from the
v12 tag instead, in a directory named after the release, and derive its path
from VERSION so v13 updates the version, both hashes and the directory
together.

v12 binds the links present when the page has loaded, so the browser test now
adds its links before load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pinned mode loaded the main script from the CDN or the custom domain and, for
a custom domain, waited until an administrator pasted an approved hash. It
now runs dist/v12/app.js, dist/v12/custom/app.js and dist/v12/auto-events.js
from the scripts v12 release archive, bundled unmodified with fixed hashes.

The custom-domain build sends data to the domain it is served from, so the
plugin fills in the saved domain, as the custom-domain server does, and saves
the result in uploads/simpleanalytics/. If uploads is not writable, visitors
get the bundled default script and administrators see a warning. This removes
the hash field, its approval, and the paused state. Uninstalling removes the
written scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simpleanalytics-agent simpleanalytics-agent added the change: needs review Significant or emergency change affecting security, data protection, or stability label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change: needs review Significant or emergency change affecting security, data protection, or stability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants