Repository navigation
fix(flame): run onLoad on every matching file when the filter has the g or y flag - #482
Conversation
… g or y flag runOnLoad called handler.filter.test(path) on the plugin's own RegExp. With the g or y flag, test() resumes from lastIndex, so every other matching file skipped the handler and was built from its unchanged source. A redaction plugin registered with /\.mdx$/g left "SECRET" in docs/b.mdx and docs/d.mdx while the build still succeeded. onLoad now copies the filter once without g and y, so each path is matched from the start. A filter that is not a RegExp is rejected in setup() instead of crashing the build in runOnLoad. The plugin docs and JSDoc showed required-option checks as a throw in onStart. Execution hooks only log their errors, so that check never stopped the build. The examples now check options in setup(), where an error stops the build, and the Error Isolation section says not to rely on an execution hook for something the site must never ship without.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
I reviewed the onLoad filter fix, its regression tests, and the doc and JSDoc changes that move required-option checks out of onStart (mode: senior, because this touches plugin execution). Verdict: READY.
- Stateless
onLoadmatching:onLoad()now stores a copy of the filter withoutg/y, sorunOnLoad'shandler.filter.test(path)matches every path from index 0. The plugin's ownRegExpis not mutated. - Filter type check at registration: a filter that is not a
RegExpnow throws aTypeErrorinsetup(). Before, it threw fromrunOnLoadpartway through the build. I checked that this error stops the build:plugin.setup(builder)is awaited without atryinbuild.ts,build.impl.ts,server.tsandserver.impl.ts, so the throw propagates. - Regression tests: the
/\.mdx$/gytest fails onmain. WithyandlastIndexat 0,docs/a.mdxnever matches, so none of the four files are redacted. The string-filter test covers the new throw. I rannpx vitest run .docu/__tests__/plugin.test.tsinpackages/flameafter building the workspace deps: all 49 tests pass.oxlintis clean on the changed TS files. - Docs move validation to
setup(): the claim thatonStarterrors are only logged matchesrunOnStart. Factory errors are rethrown byplugin-loader.ts, andbuild.configexists onPluginBuilder, so the new validator example works as written. - Changeset:
@docubook/flamepatch. This fits a bug fix with no API shape change.
One semantic note, not a blocker: removing y also removes its "match starting at index 0" behavior. A filter like /docs\//y used to match only paths that start with docs/, and now matches docs/ anywhere in the path. The old behavior was already broken for that case (it alternated between matching and not), and the JSDoc now says the g and y flags are ignored, so this looks like the right call. A filter that should only match at the start of the path needs ^.
claude-opus-5-5 | 𝕏

Summary
Found in a security audit of flame's plugin system. A plugin's
onLoadhandler was skipped on every other matching file when itsfilterhad thegoryflag. The skipped files were built from their unchanged source and the build still succeeded. A plugin that removes internal content inonLoadwould have shipped that content on half the pages.Cause
runOnLoadcalledhandler.filter.test(path)on the plugin's ownRegExp. Withgory,RegExp#testresumes fromlastIndex, so after a match the next path is tested from the wrong position and fails.Reproduced with a redaction handler on
/\.mdx$/gover four files:Fix
onLoadcopies the filter once at registration withoutgandy, so every path is matched from the start. The plugin's ownRegExpis not mutated.RegExpnow throws[plugin] onLoad requires a RegExp \filter`insetup(). Before, it threw aTypeErrorfromrunOnLoad` partway through the build.PluginBuilder.onLoadJSDoc says thegandyflags are ignored.@docubook/flamepatch.Docs: required options belong in
setup()The plugin guide, the
onStarthook reference and theonStartJSDoc all showed required-option checks as athrowinonStart. Execution hooks only log their errors, so that check never stopped the build.build.configinsetup(), where an error stops the build.setup(). A new paragraph says not to rely on an execution hook for something the site must never ship without.onStartexamples now warn instead of throwing. The lifecycle diagram labelssetupas the place to validate.Runtime error handling is unchanged.
Verification
plugin.test.ts: a/\.mdx$/gyfilter transforms all four files, and a string filter is rejected. Both fail on the builder frommainand pass with this change.oxlint, andtsc --noEmitpass. lint-staged (Prettier, oxlint), the pre-push hooks andscripts/check-release-plan.mjs(6 scenarios) pass.Not in this PR
Other findings from the audit, left for separate changes:
<script>frominjectHead/injectBodygets no nonce in the build, so the page's meta CSP blocks it in production.flame previewadds the nonce to every inline script throughinjectNonce, so such a script runs in preview and fails once deployed. The analytics example in the plugin guide is affected. A fix needs a decision: either flame adds the nonce to plugin injections only, orPageContextexposes the page nonce to plugins.