Files and paths (IAWL ideas 12, 13, 36): resolved --dest, starter refuses links and escaping paths, Office ZIP entries with trailing dots, proxy matcher ends api/admin/_next at /

- iapl-skills: --dest is compared with the project root after resolving links; a folder that is the root or holds it (.., /) is refused
- starter: collectBundle refuses symbolic links (their target would ship in the published bundle); writeFiles refuses absolute or escaping paths
- form files: a program inside a DOCX/XLSX is found with trailing dots or spaces (Windows drops them)
- proxy matcher: (?!(?:api|admin|_next)(?:/|$)|...) so /administracja, /apis get the proxy; doctor rule proxy-matcher reports the old literal
- pnpm: @swc/core in ignoredBuiltDependencies (its postinstall only checks the native binary, already installed)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 20:14:59 +01:00
co-authored by Claude Opus 5.5
parent e821d52d19
commit 498b3dbf38
21 changed files with 252 additions and 26 deletions
+8
View File
@@ -493,6 +493,14 @@ describe('security and deep status', () => {
expect(rules(await doctor(root, ['security']))).toContain('csp:info')
expect(rules(await doctor(root, ['csp'], { config: { seen: { 'csp-report-only': '2026-09-01' } } }))).toEqual(['csp:warning'])
})
test('proxy-matcher: a lookahead that does not end api / admin / _next at "/" is a warning; the 1.17.1 literal is not', async () => {
const proxy = (matcher: string) => project({ ...base(), 'src/proxy.ts': `export const config = { matcher: ['${matcher}'] }` })
expect(rules(await doctor(proxy('/((?!api|admin|_next|.*\\\\..*).*)'), ['proxy-matcher']))).toEqual(['proxy-matcher:warning'])
expect(rules(await doctor(proxy('/((?!api|cms|_next|.*\\\\..*).*)'), ['proxy-matcher']))).toEqual(['proxy-matcher:warning'])
expect(rules(await doctor(proxy('/((?!(?:api|admin|_next)(?:/|$)|.*\\\\..*).*)'), ['proxy-matcher']))).toEqual([])
expect(rules(await doctor(project(base()), ['proxy-matcher']))).toEqual([])
})
test('client-hints: withSecurityConfig inside withPayload is reported (info); outside, or kept on purpose, is not', async () => {
const inner = project(next('export default withPayload(\n withSecurityConfig(nextConfig))'))
expect(rules(await doctor(inner, ['client-hints']))).toEqual(['client-hints:info'])
+7
View File
@@ -367,6 +367,13 @@ describe('3 · refused files leave no submission and send no e-mail', () => {
await refused([{ name: 'cv.docx', data: ARCHIVE }], notAcceptable('cv.docx')) // a ZIP that is not a Word file
})
test('a program inside an Office file is found also with trailing dots or spaces (Windows drops them)', async () => {
for (const entry of ['word/setup.exe', 'word/setup.exe.', 'word/setup.exe ', 'word/setup.EXE. .', 'word/vbaProject.bin.']) {
const data = zip({ '[Content_Types].xml': '<Types/>', 'word/document.xml': '<w:document/>', [entry]: 'x' })
await refused([{ name: 'cv.docx', data }], notAcceptable('cv.docx'))
}
})
test('extra files: more than the field allows, a file under a key that is no File field', async () => {
await refused(
[{ name: 'a.pdf', data: PDF }, { name: 'b.pdf', data: PDF }],
+60
View File
@@ -0,0 +1,60 @@
/**
* `iapl-skills --dest`: the "not the project root" rule is checked on RESOLVED paths. Before 1.17.1 the check
* compared the paths as typed, so `--dest root-link` (a link to `.`), `--dest ..` or `--dest /` passed it, and the
* run removed the `iapl-*` folders of the project root, its parent or the filesystem root (IAWL idea 13).
*/
import { spawnSync } from 'node:child_process'
import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { afterAll, describe, expect, test } from 'vitest'
const bin = path.resolve(import.meta.dirname, '../bin/iapl-skills.mjs')
const made: string[] = []
afterAll(() => {
for (const dir of made) {rmSync(dir, { force: true, recursive: true })}
})
/** A throw-away project: a parent folder holding `project/` with an `iapl-mine` folder in its root. */
function project() {
const parent = realpathSync(mkdtempSync(path.join(tmpdir(), 'iapl-skills-dest-')))
made.push(parent)
const dir = path.join(parent, 'project')
mkdirSync(path.join(dir, 'iapl-mine'), { recursive: true })
writeFileSync(path.join(dir, 'iapl-mine', 'keep.txt'), 'the project root holds this folder')
mkdirSync(path.join(parent, 'iapl-next-door'))
return { dir, parent }
}
const run = (cwd: string, dest: string) =>
spawnSync(process.execPath, [bin, '--dest', dest, '--no-pointer'], { cwd, encoding: 'utf8' })
describe('iapl-skills --dest is judged after the path is resolved', () => {
test('a link to the project root is refused and the root keeps its iapl-* folders', () => {
const { dir } = project()
symlinkSync('.', path.join(dir, 'root-link'))
const result = run(dir, 'root-link')
expect(result.status, result.stdout).toBe(1)
expect(result.stderr).toMatch(/not the project root/)
expect(existsSync(path.join(dir, 'iapl-mine', 'keep.txt'))).toBe(true)
})
test('a folder that holds the project (the parent, the filesystem root) is refused', () => {
const { dir, parent } = project()
for (const dest of ['..', '/', parent]) {
const result = run(dir, dest)
expect([dest, result.status]).toEqual([dest, 1])
}
expect(existsSync(path.join(parent, 'iapl-next-door'))).toBe(true)
})
test('a folder inside the project, a new one, or one elsewhere still works', () => {
const { dir, parent } = project()
expect(run(dir, '.agents/skills').status).toBe(0)
expect(existsSync(path.join(dir, '.agents/skills/iapl-setup/SKILL.md'))).toBe(true)
const shared = path.join(parent, 'shared-skills')
expect(run(dir, shared).status).toBe(0)
expect(existsSync(path.join(shared, 'iapl-setup/SKILL.md'))).toBe(true)
expect(existsSync(path.join(dir, 'iapl-mine', 'keep.txt'))).toBe(true)
})
})
+38
View File
@@ -0,0 +1,38 @@
/**
* The documented proxy matcher, compiled by Next's own code (the function `next build` uses for `config.matcher`):
* `api`, `admin` and `_next` are skipped only as a whole first segment. Before 1.17.1 `/administracja`, `/admin-guide`
* or `/apis` skipped the proxy as well (IAWL idea 36: a deny rule by name must end at "/").
*/
import { readFileSync, realpathSync } from 'node:fs'
import { createRequire } from 'node:module'
import path from 'node:path'
import { describe, expect, test } from 'vitest'
import { DEFAULT_PROXY_MATCHER } from '../src/modules/i18n/createProxy.js'
const root = path.resolve(import.meta.dirname, '..')
const next = realpathSync(path.join(root, 'node_modules/next'))
const { getMiddlewareMatchers } = createRequire(import.meta.url)(path.join(next, 'dist/build/analysis/get-page-static-info.js')) as {
getMiddlewareMatchers: (matchers: string[], nextConfig: object) => { regexp: string }[]
}
const runs = (matcher: string) => {
const re = new RegExp(getMiddlewareMatchers([matcher], {})[0]!.regexp)
return (pathname: string) => re.test(pathname)
}
describe('the proxy matcher', () => {
test('skips /api, /admin and /_next as whole segments and files; runs on pages that only START with those letters', () => {
const proxy = runs(DEFAULT_PROXY_MATCHER[0]!)
for (const skipped of ['/api', '/api/users', '/api/ipal/hit', '/admin', '/admin/', '/admin/collections/users', '/_next/static/chunk.js', '/robots.txt', '/sitemap.xml']) {
expect([skipped, proxy(skipped)]).toEqual([skipped, false])
}
for (const page of ['/', '/o-nas', '/pl/o-nas', '/administracja', '/admin-guide', '/apis', '/api-docs', '/_nextish', '/md/pl/o-nas']) {
expect([page, proxy(page)]).toEqual([page, true])
}
})
test('the reference site uses the same literal (Next reads it statically, it cannot be imported)', () => {
const proxyFile = readFileSync(path.join(root, 'reference/src/proxy.ts'), 'utf8')
expect(proxyFile).toContain(`matcher: ['${DEFAULT_PROXY_MATCHER[0]!.replace(/\\/g, '\\\\')}']`)
})
})
+49 -2
View File
@@ -1,4 +1,5 @@
import { existsSync, rmSync, writeFileSync } from 'node:fs'
import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
@@ -29,7 +30,7 @@ import {
unpackBundle,
validateAnswers,
} from '../src/exports/starter.js'
import { externalSkillNames, resolveExternal } from '../src/modules/starter/cli.js'
import { externalSkillNames, resolveExternal, writeFiles } from '../src/modules/starter/cli.js'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const reference = path.join(root, 'reference')
@@ -257,3 +258,49 @@ describe.runIf(existsSync(path.join(reference, 'starter.manifest.json')))('start
expect(files['src/instrumentation.ts']).not.toContain('cookieCrawl')
})
})
describe('starter: links and paths (IAWL ideas 12, 13)', () => {
const site = () => {
const dir = mkdtempSync(path.join(tmpdir(), 'iapl-starter-links-'))
const manifest: StarterManifest = { drop: [], keep: ['**'], placeholders: {}, schema: 1, template: [] }
writeFileSync(path.join(dir, 'starter.manifest.json'), JSON.stringify(manifest))
writeFileSync(path.join(dir, 'pnpm-lock.yaml'), "lockfileVersion: '9.0'\n")
writeFileSync(path.join(dir, 'kept.ts'), 'export const a = 1\n')
return dir
}
it('a symbolic link is refused: its target is never read into the published bundle', () => {
const dir = site()
const secret = path.join(dir, '..', `${path.basename(dir)}-secret.txt`)
writeFileSync(secret, 'PRIVATE KEY OF SOMEBODY ELSE')
symlinkSync(secret, path.join(dir, 'leak.txt'))
mkdirSync(path.join(dir, 'outside'))
symlinkSync(path.dirname(secret), path.join(dir, 'outside', 'up'))
try {
expect(() => collectBundle(dir)).toThrow(/leak\.txt: symbolic link/)
rmSync(path.join(dir, 'leak.txt'))
// a link to a folder is not walked into either
expect(() => collectBundle(dir)).toThrow(/outside\/up: symbolic link/)
rmSync(path.join(dir, 'outside'), { force: true, recursive: true })
expect(Object.keys(collectBundle(dir).files)).toEqual(['kept.ts'])
} finally {
rmSync(dir, { force: true, recursive: true })
rmSync(secret, { force: true })
}
})
it('a bundle path outside the new folder stops the run before anything is written', () => {
const parent = mkdtempSync(path.join(tmpdir(), 'iapl-starter-paths-'))
const dir = path.join(parent, 'site')
try {
for (const bad of ['../escaped.txt', 'a/../../escaped.txt', path.join(parent, 'abs.txt')]) {
expect(() => writeFiles(dir, { 'ok.txt': 'fine', [bad]: 'no' }), bad).toThrow(/outside the new folder/)
}
expect(readdirSync(parent)).toEqual([])
writeFiles(dir, { 'ok.txt': 'fine', 'src/a/b.ts': 'x' })
expect(readdirSync(dir).sort()).toEqual(['ok.txt', 'src'])
} finally {
rmSync(parent, { force: true, recursive: true })
}
})
})