Overrides for Payload's mongoose and happy-dom advisories; doctor rule transitive-min
@payloadcms/db-mongodb pins mongoose 8.24.1 (one critical, two high, two moderate advisories, fixed by 8.24.7) and @lexical/headless 0.50 brings happy-dom 20.x (two high, fixed by 21.0.4). Payload 3.93.0 fixes neither. - reference/package.json (and so the starter): pnpm.overrides for mongoose (~8.24.10) and happy-dom (^21.0.4); pnpm audit --prod on the reference is clean - root package.json: the happy-dom override for the plugin's own dev tree - ipal-doctor: transitive-min reports mongoose 8.x < 8.24.7 (error) and happy-dom < 21.0.4 (warning) from the lockfile and prints the override line; DoctorContext.installedAll(name) - AGENT.md §4 item 12, ipal-setup, ipal-upgrade, doctor.md, README, CHANGELOG Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
7c034a07ef
commit
de8362820f
@@ -23,6 +23,11 @@ export type DoctorContext = {
|
||||
importMap: null | string
|
||||
/** Installed version of a package in the project's node_modules, or null. */
|
||||
installed: (name: string) => null | string
|
||||
/**
|
||||
* Every version of a package in the project's dependency tree, direct or transitive: from `pnpm-lock.yaml`
|
||||
* (what a deploy installs), else from `node_modules/.pnpm`, plus the top-level install. Empty when not found.
|
||||
*/
|
||||
installedAll: (name: string) => string[]
|
||||
launched: boolean
|
||||
list: (rel: string) => string[]
|
||||
live: DoctorLive | null
|
||||
@@ -121,6 +126,25 @@ export function createDoctorContext(options: ProjectOptions): DoctorContext {
|
||||
}
|
||||
}
|
||||
|
||||
const installedAll = (name: string) => {
|
||||
const escaped = name.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')
|
||||
const found = new Set<string>()
|
||||
// pnpm-lock.yaml v6+: ` [email protected]:` keys under packages: / snapshots: (the overrides: block comes before them)
|
||||
const lock = read('pnpm-lock.yaml')
|
||||
const packages = lock.slice(Math.max(0, lock.search(/^packages:\s*$/m)))
|
||||
for (const m of packages.matchAll(new RegExp(`^ {2}'?${escaped}@(\\d+\\.\\d+\\.\\d+[\\w.+-]*)`, 'gm'))) {found.add(m[1])}
|
||||
if (!found.size) {
|
||||
const dir = new RegExp(`^${escaped.replace('\\/', '\\+')}@(\\d+\\.\\d+\\.\\d+[^_(]*)`)
|
||||
for (const entry of list('node_modules/.pnpm')) {
|
||||
const m = entry.match(dir)
|
||||
if (m) {found.add(m[1])}
|
||||
}
|
||||
}
|
||||
const top = installed(name)
|
||||
if (top) {found.add(top)}
|
||||
return [...found]
|
||||
}
|
||||
|
||||
let pkg: DoctorContext['pkg'] = {}
|
||||
try {
|
||||
pkg = JSON.parse(read('package.json') || '{}') as DoctorContext['pkg']
|
||||
@@ -166,6 +190,7 @@ export function createDoctorContext(options: ProjectOptions): DoctorContext {
|
||||
exists,
|
||||
importMap: adminDir ? `${src}app/(payload)/${adminDir}/importMap.js` : null,
|
||||
installed,
|
||||
installedAll,
|
||||
launched: config.launched ?? launchedInAgents,
|
||||
list,
|
||||
live: options.live ?? null,
|
||||
|
||||
@@ -8,6 +8,28 @@ export const NEXT_MIN_SAFE = '16.4.5'
|
||||
/** The version the plugin, the reference site and the starter use. */
|
||||
export const NEXT_RECOMMENDED = '16.4.6'
|
||||
|
||||
/**
|
||||
* Packages from Payload's own dependency tree that Payload pins below a security fix (AGENT.md §4 item 12). Only the
|
||||
* project's lockfile can lift them, with a `pnpm.overrides` entry. `major` limits the check to the line Payload uses.
|
||||
*/
|
||||
export const TRANSITIVE_MIN_SAFE: { major?: number; min: string; name: string; override: string; severity: 'error' | 'warning'; why: string }[] = [
|
||||
{
|
||||
name: 'mongoose',
|
||||
major: 8,
|
||||
min: '8.24.7',
|
||||
override: '"mongoose@>=8 <8.24.7": "~8.24.10"',
|
||||
severity: 'error',
|
||||
why: 'GHSA-pcrw-h46h-c93h (critical, sanitizeFilter not applied on countDocuments) and four more; @payloadcms/db-mongodb pins 8.24.1',
|
||||
},
|
||||
{
|
||||
name: 'happy-dom',
|
||||
min: '21.0.4',
|
||||
override: '"happy-dom@<21.0.4": "^21.0.4"',
|
||||
severity: 'warning',
|
||||
why: 'GHSA-c8p4-j97h-3vg8 and GHSA-834v-8h66-3h79 (high); comes with @payloadcms/richtext-lexical → @lexical/headless',
|
||||
},
|
||||
]
|
||||
|
||||
export const versionRules: DoctorRule[] = [
|
||||
{
|
||||
id: 'plugin-installed',
|
||||
@@ -58,6 +80,27 @@ export const versionRules: DoctorRule[] = [
|
||||
group: 'versions',
|
||||
source: 'static',
|
||||
},
|
||||
{
|
||||
id: 'transitive-min',
|
||||
check: (ctx) => {
|
||||
const out: RuleFinding[] = []
|
||||
for (const dep of TRANSITIVE_MIN_SAFE) {
|
||||
const old = ctx.installedAll(dep.name).filter((v) => (dep.major === undefined || parseVersion(v)?.[0] === dep.major) && lt(v, dep.min))
|
||||
if (old.length) {
|
||||
out.push({
|
||||
file: 'package.json',
|
||||
fix: `add ${dep.override} to pnpm.overrides in package.json, then pnpm install (AGENT.md §4 item 12)`,
|
||||
message: `${dep.name} ${old.join(', ')} < ${dep.min} — ${dep.why}`,
|
||||
severity: dep.severity,
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
},
|
||||
docs: 'docs/agent/AGENT.md#4-next-16--rendering-seo-build',
|
||||
group: 'versions',
|
||||
source: 'static',
|
||||
},
|
||||
{
|
||||
id: 'node-22',
|
||||
check: (ctx) => {
|
||||
|
||||
Reference in New Issue
Block a user