From 71ab7a1c8b50df15cd2be9f877cb9ddb0a5bd958 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 13 Nov 2026 20:02:15 +0100 Subject: [PATCH 01/10] Harden option actions, tracking, and release workflows --- .distignore | 5 + .github/workflows/deploy.yml | 11 +- .github/workflows/lint.yml | 13 + .github/workflows/security.yml | 2 +- README.md | 18 ++ composer.json | 2 +- js/admin-script.js | 68 +++-- package.json | 1 + scripts/validate-known-plugins.php | 72 +++++ src/autoload.php | 4 + src/class-admin-page.php | 15 +- src/class-database.php | 195 ++++++++++++-- src/class-map-plugin-to-options.php | 4 + src/class-plugin.php | 36 ++- src/class-protected-options.php | 194 +++++++++++++ src/class-rest.php | 404 ++++++++++++++++------------ tests/admin-hardening.test.cjs | 106 ++++++++ tests/hardening.php | 362 +++++++++++++++++++++++++ uninstall.php | 2 + 19 files changed, 1291 insertions(+), 223 deletions(-) create mode 100644 scripts/validate-known-plugins.php create mode 100644 src/class-protected-options.php create mode 100644 tests/admin-hardening.test.cjs create mode 100644 tests/hardening.php diff --git a/.distignore b/.distignore index 21c4732..154cc8a 100644 --- a/.distignore +++ b/.distignore @@ -13,3 +13,8 @@ phpunit.xml.dist README.md composer.json composer.lock + +package.json +package-lock.json +/node_modules +/scripts diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1dc1b86..2bff4dd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,9 @@ on: release: types: [released] +permissions: + contents: write + jobs: deploy_to_wordpress_org: name: Deploy release @@ -11,12 +14,14 @@ jobs: steps: # Checkout the code - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false # Optional: if we add a build step to the plugin, we can run it here. # Deploy the plugin to WordPress.org - name: WordPress plugin deploy id: deploy - uses: 10up/action-wordpress-plugin-deploy@stable + uses: 10up/action-wordpress-plugin-deploy@54bd289b8525fd23a5c365ec369185f2966529c2 # stable with: generate-zip: true env: @@ -25,7 +30,7 @@ jobs: # After the deploy, we also want to create a zip and upload it to the release on Github. We don't want # users to have to go to the repository to find our plugin :). - name: Upload release asset - uses: Shopify/upload-to-release@master + uses: Shopify/upload-to-release@d0164d4ca84081447a4c6751d3bae0e834c501de # master with: name: ${{ github.event.repository.name }}.zip path: ${{ steps.deploy.outputs.zip-path }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ba843cf..9443ef4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -70,3 +70,16 @@ jobs: - name: Lint known plugins file run: composer lint-known-plugins + + javascript-regressions: + name: Admin action regressions + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + - name: Test exact option names and deletion confirmation + run: node --test tests/admin-hardening.test.cjs diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index a57a11f..df98652 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest # Don't run the cronjob in this workflow on forks. - if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'Emilia-Capital') + if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository == 'ProgressPlanner/aaa-option-optimizer') steps: - name: Checkout code diff --git a/README.md b/README.md index cba8259..d6c7098 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,18 @@ starting the name with AAA made sense. Yes!! Backup your database. +### Who can view option values? + +Every REST route requires `manage_options`. Option values can include API keys, SMTP passwords and licence keys, and the tables return these values to authorized administrators. This also applies to site administrators on multisite. Only enable the plugin where those administrators are trusted to inspect all site options. + +### Which actions are protected? + +Essential WordPress options, including site URLs, active plugins, theme settings and the current site's roles option, cannot be deleted, created with a false value, or have their autoload state changed through this plugin. Single and bulk deletion require confirmation in the admin screen. Autoload changes preserve the stored value and use WordPress's cache-aware autoload API. + +### Why are unused-option recommendations paused? + +Tracking retains at most 10,000 distinct names and records at most 1,000 distinct names per request. When a limit is reached or a tracking write fails, the plugin marks observations incomplete and pauses unused-option recommendations. Existing recorded counts can still increase. Older oversized tables are reduced to the limit on the next tracking write. Reset tracking to start a fresh observation period. + ### How can I add recognized plugins? Please do a pull request via GitHub on [this file](https://github.com/ProgressPlanner/aaa-option-optimizer/blob/develop/known-plugins/known-plugins.json) in the plugin. @@ -40,3 +52,9 @@ Please do a pull request via GitHub on [this file](https://github.com/ProgressPl ### How can I report security bugs? You can report security bugs through the Patchstack Vulnerability Disclosure Program. The Patchstack team help validate, triage and handle any security vulnerabilities. [Report a security vulnerability.](https://patchstack.com/database/vdp/aaa-option-optimizer) + +## Development checks + +Run `composer lint`, `composer check-cs`, `composer phpstan`, and `composer lint-known-plugins` with the development dependencies installed, and `npm run test:hardening:js` for the admin action regressions. The plugin-map validator requires an object keyed by plugin slug, with exactly a non-empty `name` and a non-empty array of unique string `option_prefixes` per entry. + +Run `wp eval-file /path/to/aaa-option-optimizer/tests/hardening.php` only on a disposable WordPress installation with an administrator at user ID 1 and `define( 'AAAOO_DISPOSABLE_TEST_SITE', true );` in its configuration. The test creates and deletes fixtures and resets tracking data. It covers REST validation, exact option names, protected options, failed autoload updates, raw-value preservation, malformed sorting, and tracking limits. diff --git a/composer.json b/composer.json index c1643cc..bc1ef6a 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "@php -r \"exit( intval( is_null( json_decode( file_get_contents( './.wordpress-org/blueprints/blueprint.json' ) ) ) ) );\"" ], "lint-known-plugins": [ - "@php -r \"exit( intval( is_null( json_decode( file_get_contents( './known-plugins/known-plugins.json' ) ) ) ) );\"" + "@php scripts/validate-known-plugins.php" ], "phpstan": [ "@php ./vendor/bin/phpstan analyse --memory-limit=2048M" diff --git a/js/admin-script.js b/js/admin-script.js index 35d5f2e..abb11ba 100644 --- a/js/admin-script.js +++ b/js/admin-script.js @@ -106,7 +106,7 @@ jQuery( document ).ready( function () { responsive: true, columns: getColumns( selector ), rowId( data ) { - return generateRowId( data.name ); + return selector.substring( 1 ) + '-' + generateRowId( data.name ); }, initComplete() { this.api().columns( 'source:name' ).every( filterSetup ); @@ -122,6 +122,14 @@ jQuery( document ).ready( function () { headers: { 'X-WP-Nonce': aaaOptionOptimizer.nonce }, type: 'GET', dataSrc( json ) { + if ( + json.tracking_limited && + ! jQuery( '#aaa-tracking-limited' ).length + ) { + jQuery( '

' ) + .text( aaaOptionOptimizer.i18n.trackingLimited ) + .insertBefore( selector ); + } tableSources[ selector ] = json.sources || []; return json.data; }, @@ -444,7 +452,7 @@ jQuery( document ).ready( function () { `, ]; - return actions.join( '' ); + return ( row.protected ? actions.slice( 0, 2 ) : actions ).join( '' ); } /** @@ -455,6 +463,9 @@ jQuery( document ).ready( function () { * @return {string} - The HTML for the value column. */ function renderNonExistingOptionsColumn( row ) { + if ( row.protected ) { + return ''; + } return `