Skip to content

fix: small security cleanups (closes #121, #123, #128) - #201

Merged
ivdimova merged 1 commit into
devfrom
fix/v0-11-small-security
May 12, 2026
Merged

ivdimova merged 1 commit into
devfrom
fix/v0-11-small-security

Conversation

@pluginslab

Copy link
Copy Markdown
Owner

Summary

Third of three security PRs. Three small Plugin Checker items — two real edits and one already-done close-out.

Net: +18 / -5 lines, 2 files touched.

Closes

#121 — Escape output in `functions-abilities.php`

Previous code passed `sprintf()` output directly to `_doing_it_wrong()` with a misleading phpcs:ignore claiming "output is escaped by _doing_it_wrong()". That's not actually true — `_doing_it_wrong` forwards the message to `trigger_error()`, which in WP_DEBUG mode can reach an admin notice / error log without HTML escaping.

In practice the ability ID is developer-controlled (third-party plugins choose their own namespace), but Plugin Checker (rightly) wants defense in depth here.

Fix: wrap the `sprintf` in `esc_html()` and drop the misleading ignore comment. No behavior change in the common path (the format string has no HTML), but the safety contract is now explicit.

#123 — `sw-loader.php` direct access + `readfile()`

This file is intentionally browser-accessible — it's the URL the browser fetches when registering the Service Worker, before WordPress is loaded. `ABSPATH` is never defined here, and `WP_Filesystem` is unavailable.

Fix: kept the existing structure (it's correct), added a docblock explaining why no ABSPATH guard is possible, and a single `phpcs:ignore` on the `readfile()` call with rationale (single asset, hard-coded `DIR` path, no traversal vector).

#128 — `db-optimize.php` uncached query

Already resolved by the existing `phpcs:ignore` on line 81 (covers both `DirectQuery` and `NoCaching`). No changes needed — closing as already-fixed.

Verification

  • `composer lint` — 0 errors, 0 warnings (was 1 warning on sw-loader.php)
  • `npm test` — 96 passing, unchanged

Where this leaves v0.11

Bucket Status
Housekeeping (#198) Open, Ivelina reviewing
Security PR A (#199) Open, Ivelina reviewing
Security PR B (#200) Open, Ivelina reviewing
Security PR C (this) Open, Ivelina reviewing
Compliance — trademark rename (#125) Not started
Compliance — readme.txt headers (#124) Not started
Critical bug — role-capabilities-check sync (#188) Not started
Critical bug — Activate/Deactivate buttons (#179) Not started
Critical bug — Actions filtered post-tool (#181) Not started
Critical bug — Don't preload model when sidebar hidden (#116) Not started

Test plan

  • Build check passes
  • PHP lint passes (specifically: 0 warnings repo-wide)
  • JS lint passes
  • Unit tests pass
  • Manual: register an invalid ability ID (`'BAD ID'`) via PHP and confirm the resulting `_doing_it_wrong` notice renders escaped HTML

🤖 Generated with Claude Code

…r rationale (closes #121, #123, #128)

Three Plugin Checker items that turned out to be small / partially-done.

#121 — Escape output in functions-abilities.php
  The previous code passed sprintf() output directly to _doing_it_wrong()
  with a misleading phpcs:ignore claiming "output is escaped by
  _doing_it_wrong()". That's not true — _doing_it_wrong forwards the
  message to trigger_error(), which in WP_DEBUG mode can reach an
  admin notice / error log without HTML escaping. The ability ID is
  developer-controlled in practice, but Plugin Checker (rightly) wants
  defense in depth here.

  Fix: wrap the sprintf in esc_html() and drop the misleading ignore
  comment. No behavior change in the common path (the format string
  has no HTML), but the safety contract is now explicit.

#123 — sw-loader.php direct access + readfile()
  This file is intentionally browser-accessible — it's the URL the
  browser fetches when registering the Service Worker, before
  WordPress is loaded. ABSPATH is never defined here and WP_Filesystem
  is unavailable.

  Fix: kept the existing structure (it's correct), added a docblock
  explaining why no ABSPATH guard is possible, and a single
  phpcs:ignore on the readfile() call with rationale (single asset,
  hard-coded __DIR__ path, no traversal vector).

#128 — db-optimize.php uncached query
  Already resolved by the existing phpcs:ignore on line 81 (covers
  WordPress.DB.DirectDatabaseQuery.DirectQuery and .NoCaching). No
  changes needed — closing as already-fixed.

Verification:
  composer lint — 0 errors, 0 warnings (was 1 warning on sw-loader.php)
  npm test — 96 passing, unchanged

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@ivdimova ivdimova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Both fixes are correct. esc_html() wrapping is a genuine security fix — _doing_it_wrong() does not escape its input. readfile() swap is appropriate for streaming. sw-loader.php rationale comment correctly justifies the ABSPATH exception.

@ivdimova
ivdimova merged commit e752d16 into dev May 12, 2026
4 checks passed
@ivdimova
ivdimova deleted the fix/v0-11-small-security branch May 12, 2026 21:50
ivdimova pushed a commit that referenced this pull request May 12, 2026
Minimum WP.org-required rename ahead of plugin directory submission.
What WordPress.org's Plugin Checker actually rejects:
  - Plugin Name containing "WP" (treats it as a WordPress lookalike)
  - Function names beginning with wp_ (looks like core)
  - Text Domain not matching the submission slug

What changed:
  - Plugin Name header: "WP Agentic Admin" → "Agentic Admin for WordPress"
  - Plugin URI: pluginslab.com/wp-agentic-admin → pluginslab.com/agentic-admin
  - Text Domain header: wp-agentic-admin → agentic-admin
  - readme.txt header: === Agentic Admin for WordPress ===
  - README.md heading + body: same display-name updates
  - i18n text-domain string in all __()/esc_html__()/etc. calls:
    'wp-agentic-admin' → 'agentic-admin'
  - PHP function prefix: wp_agentic_admin_* → agentic_admin_*
    (touches register fns, helpers, the manifest entries that
    reference function names by string, the abilities, REST callbacks)
  - phpcs.xml.dist: updated text_domain + prefixes properties
    accordingly. WP_AGENTIC_ADMIN_* constants and WPAgenticAdmin
    namespace kept in the allowed prefix list (not WP.org-checked,
    deliberately out of scope for this PR).

What stayed (out of scope, not WP.org-blocking):
  - Local folder name (wp-agentic-admin/)
  - PHP constants WP_AGENTIC_ADMIN_*
  - PHP namespace WPAgenticAdmin
  - JS global wpAgenticAdmin
  - Ability ID prefix (wp-agentic-admin/*)
  - REST namespace (wp-agentic-admin/v1)
  - Option key prefix (wp_agentic_admin_*)

These can land in a v0.12 cosmetic-rename PR if/when we want full
consistency. Folder rename specifically should be its own deliberate
move with migration handling for any dev-install Option data.

Verification:
  - Playground reload: plugin still active, shown as "Agentic Admin
    for WordPress" in plugin list
  - agentic_admin_resolve_enabled_abilities() returns 33 abilities,
    every registrar function_exists() check passes
  - composer lint: 0 errors (1 pre-existing readfile warning on
    sw-loader.php, fixed by PR #201)
  - npm test: 96 passing, unchanged
  - npm run build: clean

Note: this PR also covers the README.md plugin-name update from
PR #202 (which renamed "WP-Agentic-Admin" → "WP Agentic Admin").
After this lands, #202 should be closed as superseded.

Net: 91 files changed, +1021 / -1015 (close to zero — mechanical renames,
no logic changes).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ivdimova pushed a commit that referenced this pull request May 12, 2026
* fix: rename to "Agentic Admin for WordPress" (closes #125, #124)

Minimum WP.org-required rename ahead of plugin directory submission.
What WordPress.org's Plugin Checker actually rejects:
  - Plugin Name containing "WP" (treats it as a WordPress lookalike)
  - Function names beginning with wp_ (looks like core)
  - Text Domain not matching the submission slug

What changed:
  - Plugin Name header: "WP Agentic Admin" → "Agentic Admin for WordPress"
  - Plugin URI: pluginslab.com/wp-agentic-admin → pluginslab.com/agentic-admin
  - Text Domain header: wp-agentic-admin → agentic-admin
  - readme.txt header: === Agentic Admin for WordPress ===
  - README.md heading + body: same display-name updates
  - i18n text-domain string in all __()/esc_html__()/etc. calls:
    'wp-agentic-admin' → 'agentic-admin'
  - PHP function prefix: wp_agentic_admin_* → agentic_admin_*
    (touches register fns, helpers, the manifest entries that
    reference function names by string, the abilities, REST callbacks)
  - phpcs.xml.dist: updated text_domain + prefixes properties
    accordingly. WP_AGENTIC_ADMIN_* constants and WPAgenticAdmin
    namespace kept in the allowed prefix list (not WP.org-checked,
    deliberately out of scope for this PR).

What stayed (out of scope, not WP.org-blocking):
  - Local folder name (wp-agentic-admin/)
  - PHP constants WP_AGENTIC_ADMIN_*
  - PHP namespace WPAgenticAdmin
  - JS global wpAgenticAdmin
  - Ability ID prefix (wp-agentic-admin/*)
  - REST namespace (wp-agentic-admin/v1)
  - Option key prefix (wp_agentic_admin_*)

These can land in a v0.12 cosmetic-rename PR if/when we want full
consistency. Folder rename specifically should be its own deliberate
move with migration handling for any dev-install Option data.

Verification:
  - Playground reload: plugin still active, shown as "Agentic Admin
    for WordPress" in plugin list
  - agentic_admin_resolve_enabled_abilities() returns 33 abilities,
    every registrar function_exists() check passes
  - composer lint: 0 errors (1 pre-existing readfile warning on
    sw-loader.php, fixed by PR #201)
  - npm test: 96 passing, unchanged
  - npm run build: clean

Note: this PR also covers the README.md plugin-name update from
PR #202 (which renamed "WP-Agentic-Admin" → "WP Agentic Admin").
After this lands, #202 should be closed as superseded.

Net: 91 files changed, +1021 / -1015 (close to zero — mechanical renames,
no logic changes).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix: prettier formatting after rename sed (string-length nudges)

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

2 participants