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..4b08362 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@11d5960a326750d5838078e36cf38b85af677262 # v4 + - name: Setup Node.js + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # 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..ba57c24 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, the active theme's settings, salts and keys stored in the database, 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 stores up to about 10,000 distinct names. The limit is checked without locking, so concurrent requests can push slightly past it. Once it is reached, names already recorded keep counting, but a new name is dropped, and the plugin then marks observations incomplete and pauses unused-option recommendations, because a dropped name could otherwise be reported as unused. Data migrated from older versions is kept in full, even past the limit. A failed tracking write does not pause recommendations; it loses at most that request's counts. 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 be386a0..3d327ce 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,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" ], "test": [ "@php ./vendor/phpunit/phpunit/phpunit" diff --git a/js/admin-script.js b/js/admin-script.js index d2270b4..306c1aa 100644 --- a/js/admin-script.js +++ b/js/admin-script.js @@ -106,7 +106,9 @@ 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 +124,16 @@ 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 +456,7 @@ jQuery( document ).ready( function () { `, ]; - return actions.join( '' ); + return ( row.protected ? actions.slice( 0, 2 ) : actions ).join( '' ); } /** @@ -455,6 +467,9 @@ jQuery( document ).ready( function () { * @return {string} - The HTML for the value column. */ function renderNonExistingOptionsColumn( row ) { + if ( row.protected ) { + return ''; + } return `