Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Weekly update PRs, one per ecosystem, so no dependency sits on a known
# vulnerability or a deprecated version for long. All of these are build and CI
# tooling: none of them ship in the plugin zip (see .distignore).
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
groups:
npm:
patterns: [ '*' ]

- package-ecosystem: composer
directory: /
schedule:
interval: weekly
groups:
composer:
patterns: [ '*' ]

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions:
patterns: [ '*' ]
36 changes: 21 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on:
permissions:
contents: read

# A new push to a pull request supersedes the run for the previous one.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
php-lint:
name: PHP ${{ matrix.php }} syntax
Expand All @@ -18,26 +23,27 @@ jobs:
matrix:
# Floor is the plugin's "Requires PHP"; ceiling is the newest release, which
# is where the PHP 8 breakage fixed in 3.4.0 would have shown up first.
php: [ '7.4', '8.0', '8.2', '8.4', '8.5' ]
# Behavioural differences between versions are phpcs's job (PHPCompatibility).
php: [ '7.4', '8.0', '8.2', '8.4', '8.5', '8.6' ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
- name: Lint every PHP file
run: |
find . -path ./vendor -prune -o -path ./node_modules -prune -o -name '*.php' -print \
find . -path ./vendor -prune -o -path ./node_modules -prune -o -path ./build -prune -o -name '*.php' -print \
| xargs -n1 -P4 php -l

phpcs:
name: WordPress coding standards
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.5'
coverage: none
tools: composer
- run: composer install --prefer-dist --no-progress
Expand All @@ -47,10 +53,10 @@ jobs:
name: Minified assets are current
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '20'
node-version: lts/*
cache: npm
- run: npm ci
# Catches the case where fancybox.css is edited but the .min is not rebuilt -
Expand All @@ -61,14 +67,14 @@ jobs:
name: Package builds cleanly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '20'
node-version: lts/*
# Also asserts the plugin header, FBFW_VERSION, readme Stable tag and
# package.json all agree, and that no dev file leaked into the zip.
- run: npm run package
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v7
with:
name: plugin-zip
path: build/*.zip
Expand All @@ -81,10 +87,10 @@ jobs:
# Lets the action post its findings as a PR comment.
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '20'
node-version: lts/*
cache: npm
- run: npm ci

Expand Down
30 changes: 23 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ name: Deploy to WordPress.org
# said 3.4.0. Releasing from a tag makes git the source of truth and removes the
# manual SVN step where that drift crept in.
#
# Requires two repository secrets: SVN_USERNAME and SVN_PASSWORD (a WordPress.org
# account with commit access to the plugin).
# The Publish job is opt-in. It runs only when the repository variable
# WPORG_SVN_DEPLOY is `true` and needs two repository secrets, SVN_USERNAME and
# SVN_PASSWORD (a WordPress.org account with commit access to the plugin).
#
# Until then releases go to SVN by hand from the GitHub release zip, and every tag
# push still runs Pre-flight. Without the switch, each release turned this workflow
# red at the credentials step, which taught everyone to ignore a red deploy. The
# "WordPress.org matches git" workflow checks the published result either way.

on:
push:
Expand All @@ -29,10 +35,10 @@ jobs:
name: Pre-flight
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '20'
node-version: lts/*
cache: npm
- run: npm ci

Expand All @@ -54,14 +60,24 @@ jobs:
exit 1
fi

- name: Say how this tag reaches WordPress.org
if: startsWith(github.ref, 'refs/tags/') && vars.WPORG_SVN_DEPLOY != 'true'
run: |
{
echo "### Publishing is manual"
echo "WPORG_SVN_DEPLOY is not \`true\`, so this run does not publish to WordPress.org."
echo "Commit the GitHub release zip to SVN trunk and tags/${GITHUB_REF#refs/tags/}."
echo "The *WordPress.org matches git* workflow checks the result daily."
} >> "$GITHUB_STEP_SUMMARY"

deploy:
name: Publish
needs: verify
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push' && vars.WPORG_SVN_DEPLOY == 'true'
environment: wordpress-org
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

# Without this the run dies deep inside the SVN step with an authentication
# error that does not say what is actually wrong.
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: WordPress.org matches git

# Daily: the version WordPress.org serves must have a git tag, and both its
# WordPress.org download and its GitHub release zip must contain exactly what that
# tag builds. Releases reach SVN by hand, which is where 3.3.7 (never committed to
# git) and 3.4.1 (shipped while master said 3.4.0) drifted. A readme-only SVN edit,
# such as bumping "Tested up to", also fails this until it is committed to git and
# the release is re-tagged.

on:
schedule:
- cron: '23 6 * * *'
workflow_dispatch:
inputs:
version:
description: 'Version to check (default: the one WordPress.org serves)'
required: false

permissions:
contents: read

jobs:
compare:
name: Published release matches its tag
runs-on: ubuntu-latest
steps:
- name: Find the version to check
id: version
env:
REQUESTED: ${{ inputs.version }}
run: |
VERSION="$REQUESTED"
if [ -z "$VERSION" ]; then
VERSION=$(curl -fsS https://api.wordpress.org/plugins/info/1.0/fancybox-for-wordpress.json | jq -r .version)
fi
if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Not a version number: '$VERSION'"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

# The checker comes from master so an older tag is judged by the current rules.
- uses: actions/checkout@v7
with:
path: tools
sparse-checkout: bin/verify-release.mjs
sparse-checkout-cone-mode: false

- name: Check out the release tag
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
if ! git clone --quiet --depth 1 --branch "$VERSION" "https://github.com/${GITHUB_REPOSITORY}.git" release; then
echo "::error::WordPress.org serves $VERSION, but git has no $VERSION tag."
exit 1
fi

- uses: actions/setup-node@v7
with:
node-version: lts/*

- name: Compare WordPress.org and the GitHub release with the tag
working-directory: release
env:
GITHUB_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: node ../tools/bin/verify-release.mjs "$VERSION"
17 changes: 13 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ npm run verify:assets # fail if a .min file is stale — this is what CI enfo
npm run i18n # regenerate .pot, .mo and .l10n.php (needs wp-cli on PATH)
npm run package # build build/fancybox-for-wordpress-<version>.zip
npm run release:check # verify:assets + composer lint + package
composer phpcs # escaping, sanitisation, nonces, i18n, PHP 7.4–8.5 compatibility
npm run verify:release # from a tag checkout: WordPress.org zip and GitHub release asset == the tag's build
composer phpcs # escaping, sanitisation, nonces, i18n, PHP 7.4+ compatibility
composer lint # php -l across every file
```

Expand All @@ -29,7 +30,15 @@ Two guards worth knowing about, because both encode mistakes that actually happe

### Releasing

Push a version tag and `.github/workflows/deploy.yml` publishes that commit to WordPress.org SVN. It needs the `SVN_USERNAME` / `SVN_PASSWORD` repository secrets. **Do not release by hand** — 3.3.7 shipped to WordPress.org and was never committed to git, and 3.4.1 shipped while `master` still said 3.4.0. Releasing from a tag makes git the source of truth and removes the step where that drift occurred.
Git is the source of truth. 3.3.7 shipped to WordPress.org and was never committed to git, and 3.4.1 shipped while `master` still said 3.4.0, so the release order is fixed: merge to `master`, `gh release create X <zip> --target master --latest` (zip built from `master`, no `v` prefix), and only then commit **that release zip's contents** to SVN trunk and `tags/X` in one revision. Never copy the repo root into SVN.

The SVN step is manual for now. `.github/workflows/deploy.yml` runs a pre-flight on every tag push (assets current, versions agree, tag equals version), but its Publish job runs only when the repository variable `WPORG_SVN_DEPLOY` is `true` and the `SVN_USERNAME` / `SVN_PASSWORD` secrets exist. Neither is set, which keeps a tag push green instead of failing at the credentials step on every release.

`.github/workflows/release-check.yml` ("WordPress.org matches git") runs daily. It rebuilds the version WordPress.org serves from its git tag and compares it file by file with the WordPress.org download and the GitHub release asset (`bin/verify-release.mjs`). A readme-only SVN edit, such as bumping `Tested up to` in a tag, fails it until the change is in git and released. Run it by hand after an SVN commit, once the WordPress.org zip has regenerated.

PHP cross-version checks use **PHPCompatibility 10 (alpha)**. The stable 9.3.5 knows nothing after PHP 7.4, so it passed a PHP 8.1 behaviour change (`html_entity_decode()` default flags) that 10 caught. Move to 10.0 stable when it ships; the `@alpha` flags in `composer.json` are the only reason the alpha resolves. PHP_CodeSniffer stays on 3.x until WPCS supports 4.

Dependabot (`.github/dependabot.yml`) opens weekly grouped PRs for npm, Composer and Actions. All of them are build tooling; the runtime libraries (DOMPurify, fancyBox, the jQuery UI stylesheet) are vendored files and must be updated by hand.

`phpcs.xml.dist` deliberately runs a **subset** of the WordPress standard. The full `WordPress` ruleset reports 293 violations here, all of them whitespace, array alignment or missing docblocks, and zero security/i18n/compatibility problems. The rules kept are the ones that catch real defects; see the file's own `<description>` for how to adopt full formatting later.

Expand Down Expand Up @@ -113,7 +122,7 @@ Minified files ship by default; `SCRIPT_DEBUG` switches to the readable sources
| Source | Minified | Regenerate with |
| --- | --- | --- |
| `assets/js/jquery.fancybox.js` | `jquery.fancybox.min.js` | `npx terser@5 <src> --compress --mangle --comments '/^!\|licen[cs]e\|fancyBox v/i' -o <out>` |
| `assets/css/fancybox.css` | `fancybox.min.css` | `npx clean-css-cli@5 -O2 -o <out> <src>` |
| `assets/css/fancybox.css` | `fancybox.min.css` | `node bin/minify-css.mjs <src> <out>` (the clean-css library at level 2, byte-identical to `cleancss -O2`) |
| `assets/js/purify.js` | `purify.min.js` | ship both dist files from `npm pack dompurify@<version>`, stripping the `sourceMappingURL` comments |

After minifying, verify the namespace survived and the selector counts match:
Expand All @@ -139,7 +148,7 @@ Field markup follows a consistent pattern — an `.epsilon-toggle` block for boo

Releases 3.3.4 – 3.4.0 were dominated by security fixes. The risky code is structural:

- **Caption/title XSS.** DOMPurify (currently **3.4.17**, bundled) is a hard dependency of the `fancybox-for-wp` script handle. The generated `caption`, `afterLoad` and title-copy JS all route user HTML through `jQuery.fancyboxforwp.sanitize()`, which applies the `elementHtmlRules` allow-list and falls back to `jQuery("<div>").text(x).html()`. Do not go back to DOMPurify's plain `html` profile: it keeps `<style>`, form controls and `style=`, which a Contributor can reach through `data-caption`. **Never remove either path.** Keep DOMPurify current — 3.1.6 shipped for a year while vulnerable to CVE-2025-26791.
- **Caption/title XSS.** DOMPurify (currently **3.5.0**, bundled) is a hard dependency of the `fancybox-for-wp` script handle. The generated `caption`, `afterLoad` and title-copy JS all route user HTML through `jQuery.fancyboxforwp.sanitize()`, which applies the `elementHtmlRules` allow-list and falls back to `jQuery("<div>").text(x).html()`. Do not go back to DOMPurify's plain `html` profile: it keeps `<style>`, form controls and `style=`, which a Contributor can reach through `data-caption`. **Never remove either path.** Keep DOMPurify current — 3.1.6 shipped for a year while vulnerable to CVE-2025-26791.
- **Generated CSS is not escapable by `esc_html()`.** It only blocks `<`; a colour value can still close its declaration block. This is why colours go through `mfbfw_sanitize_hex_color()` and sizes through the `int` schema type. Never interpolate an unvalidated value into `mfbfw_build_css()`.
- **Intentional raw-JS injection.** `customExpression`, `extraCallsData` and the five `callbackOn*` settings are echoed through `html_entity_decode()` unescaped. Deliberate feature, gated at save on `unfiltered_html` (`mfbfw_can_edit_scripts()`, because a multisite site administrator holds `manage_options`) and `wp_strip_all_tags()`. Don't "fix" it by escaping — that breaks the feature — but don't widen it either.
- Every PHP file starts with `defined( 'ABSPATH' ) || exit;`. Keep that on new files.
Expand Down
Loading