Skip to content

Restrict analytics tracking and harden settings and releases - #58

Merged
adriaandotcom merged 6 commits into
simpleanalytics:mainfrom
jdevalk:codex/security-hardening
Nov 19, 2026
Merged

adriaandotcom merged 6 commits into
simpleanalytics:mainfrom
jdevalk:codex/security-hardening

Conversation

@jdevalk

@jdevalk jdevalk commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Analytics scripts could load on login and admin pages, and administrators without unfiltered_html could choose an arbitrary script origin through Custom Domain. This change limits tracking to front-end pages and requires an authorized save before a custom domain can serve scripts.

  • Apply tracking exclusions to automated events and always exclude multisite super admins, including those without a role on the current site.
  • Validate custom domains as hostnames and bind approval to the saved value and site; use the same approved domain for analytics, events, and noscript requests.
  • Exclude development files from WordPress.org packages and guard PHP files against direct access.
  • Make releases manually triggered on main, pin release/test actions to commit SHAs, pass shell inputs through environment variables, and restrict default token permissions while preserving the release-app integration.
  • Handle array-valued tab parameters, escape tab links and labels, and remove the external admin font request.

Upgrade note: Existing custom domains fall back to the default CDN until an administrator with unfiltered_html saves them again.

Validation: pnpm build and pnpm tests pass on the rebased branch: 28 tests, comprising 22 Chromium browser tests and six PHP regression scripts. Workflow YAML, action pins, permissions, shell interpolation, and git diff --check also pass.

Update

Changes pushed on top of this PR:

  • Existing custom domains keep working. The approval hash is removed. It disabled every existing custom domain on upgrade, after a salt rotation, and when the domain is set with WP-CLI. The unfiltered_html check on save stays and still stops multisite site administrators from changing the script origin. The upgrade note above no longer applies.
  • Warnings beside the field. A rejected domain, a user without permission trying to change it, and a saved value that can't be used are now explained inside the settings page. WordPress's own notices are hidden by the page's shadow root. Pasted URLs such as https://Stats.Example.com/ are saved as stats.example.com.
  • Network administrators are an option. Instead of always being excluded, multisite sites get a "Network administrator (Super Admin)" choice among the excluded roles, so existing sites keep collecting their visits. With no roles selected, every logged-in user is still excluded.
  • The weekly release stays. The Monday run tests new WordPress versions and releases automatically. The review suggestion on .github/workflows/release.yml restores its schedule and keeps the pinned actions, permissions and concurrency from this PR.
  • Merged current main.

Validation: all 30 browser and WordPress regression tests pass locally on WordPress 7.1.4 with PHP 8.5, plus the regression scripts on multisite. CI covers MySQL and PHP 7.4.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

jdevalk commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

CI update for commit 8ef3ad2: all ten WordPress/PHP matrix jobs passed in the E2E test run.

The only failed check is pull-request / sdlc-label. Its “Ensure SDLC labels” step fails when updating a repository label with Resource not accessible by integration. This is a workflow token-permission failure, not a failing plugin test. Since this PR comes from a fork, a repository maintainer may need to review how the labeling workflow handles fork PRs; no repository permissions or labeling workflows have been changed in this PR.

… 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>
Comment thread .github/workflows/release.yml Resolved
@simpleanalytics-agent simpleanalytics-agent added the change: needs review Significant or emergency change affecting security, data protection, or stability label Nov 18, 2026
adriaandotcom pushed a commit that referenced this pull request Nov 19, 2026
Use one validated client-IP resolver for tracking exclusions and **Add
Current IP**, so the address offered in settings is also the address
checked on visits. Normalize IPv4/IPv6 before comparison and hide the
button when no valid address is available.

Forwarded headers are no longer trusted automatically. Deployments
should configure trusted proxies at the web server or use the documented
`simpleanalytics_client_ip` filter after verifying the proxy. This
intentionally changes behavior for installations that previously relied
on unvalidated `X-Forwarded-For` values.

Fixes #40.

Validation: the WordPress regression fails on the original
forwarded-header handling and passes with the fix, covering spoofed
headers/chains, IPv6 equivalence, shared UI/filter behavior, malformed
inputs and missing addresses. The existing Add Current IP browser test
also passes. PHP syntax and diff checks pass.

Combined validation: all six proposed fixes were applied to a local
integration branch; all 23 browser and WordPress regression tests, the
asset build, PHP syntax checks and diff checks passed. GitHub workflows
currently report `action_required` for these fork pull requests.



## Update

The second paragraph above is out of date. Forwarded addresses are still
trusted: the first public address in `X-Forwarded-For` is used, skipping
private, loopback and invalid entries, and `REMOTE_ADDR` only when the
header is absent. See the update on #40 for the reasons.

Also merged current `main` and added the direct-access guard that #58
adds to every file.

**Validation:** all 24 browser and WordPress regression tests pass
locally on WordPress 7.1.4 with PHP 8.5, plus the regression scripts on
multisite. CI covers MySQL and PHP 7.4.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved client IP detection when requests pass through proxies,
including more reliable handling of forwarded addresses and IPv4/IPv6
formats.
  * Excluded IP rules now compare normalized addresses consistently.
* The IP settings page shows the resolved client IP and hides the add
button when no valid address is available.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: simple-analytics-ai[bot] <313929673+simple-analytics-ai[bot]@users.noreply.github.com>
Co-authored-by: Simple Analytics Codex <codex@simpleanalytics.invalid>
Co-authored-by: Simple Analytics Agent <343555763+simpleanalytics-agent@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Simple Analytics Agent <github-agent@adriaan.simpleanalytics.com>
@adriaandotcom
adriaandotcom merged commit af7861e into simpleanalytics:main Nov 19, 2026
1 check failed
simpleanalytics-agent added a commit to jdevalk/wordpress-plugin that referenced this pull request Nov 19, 2026
main's tree is identical to the final security hardening branch merged
above, because simpleanalytics#58 was squash-merged. Recording main as a parent with
the already-merged tree avoids replaying the same changes as conflicts.
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.

3 participants