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
+21
View File
@@ -60,6 +60,27 @@ export const securityRules: DoctorRule[] = [
group: 'security',
source: 'static',
},
{
// A matcher whose lookahead names api / admin / _next without ending them at "/" also skips every page whose
// first segment merely STARTS with those letters (/administracja, /apis): no locale redirect, and no CSP from the
// proxy on a single-locale site (IAWL idea 36, fixed in the documented literal in 1.17.1).
id: 'proxy-matcher',
check: async (ctx) => {
const file = `${ctx.src}proxy.ts`
const code = stripComments(ctx.read(file))
const loose = [...code.matchAll(/\(\?!((?:[\w-]+\|)*[\w-]+)\|/g)].map((m) => m[1]!.split('|')).find((names) => names.some((n) => ['_next', 'admin', 'api'].includes(n)))
if (!loose) {return []}
return [{
file,
fix: "matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\\\..*).*)'] (i18n.md → Next matcher)",
message: `the proxy matcher skips every path that starts with ${loose.map((n) => `"${n}"`).join(', ')} (e.g. /${loose.includes('admin') ? 'administracja' : `${loose[0]}s`}), not only those folders: no locale redirect, no proxy CSP there`,
severity: 'warning',
}]
},
docs: 'docs/i18n.md',
group: 'security',
source: 'static',
},
{
id: 'client-hints',
check: async (ctx) => {
+5 -2
View File
@@ -106,7 +106,10 @@ const REQUIRED_ENTRIES: Record<string, string[]> = {
xlsx: ['[Content_Types].xml', 'xl/workbook.xml'],
}
const RISKY_ENTRY = /\.(?:bat|cmd|com|dll|exe|hta|jar|js|lnk|msi|ps1|scr|sh|vbs)$/i
// Trailing dots and spaces count as the end of the name: Windows drops them when it writes the file, so an entry
// `setup.exe.` or `setup.exe ` becomes `setup.exe` once extracted.
const RISKY_ENTRY = /\.(?:bat|cmd|com|dll|exe|hta|jar|js|lnk|msi|ps1|scr|sh|vbs)[.\s]*$/i
const MACRO_ENTRY = /vbaProject\.bin[.\s]*$/i
const indexOfBytes = (bytes: Uint8Array, needle: readonly number[]) => {
outer: for (let i = 0; i <= bytes.length - needle.length; i++) {
@@ -188,7 +191,7 @@ export async function checkFileContent(
if (!entries) {return 'signature'}
const names = new Set(entries.map((e) => e.name))
if (required.some((name) => !names.has(name))) {return 'signature'}
if (entries.some((e) => e.encrypted || /vbaProject\.bin$/i.test(e.name) || RISKY_ENTRY.test(e.name))) {return 'content'}
if (entries.some((e) => e.encrypted || MACRO_ENTRY.test(e.name) || RISKY_ENTRY.test(e.name))) {return 'content'}
}
if ((key === 'doc' || key === 'xls') && oleHasMacros(bytes)) {return 'content'}
if (key === 'pdf' && strictPdf && pdfHasActiveContent(bytes)) {return 'content'}
+1 -1
View File
@@ -81,7 +81,7 @@ type CreateProxyOptions = {
* import { createProxy, DEFAULT_PROXY_MATCHER } from '@intecion/ipal-kit'
* import { i18nConfig } from '@/i18n.config'
* export const proxy = createProxy(i18nConfig, { NextResponse, markdown: true })
* export const config = { matcher: ['/((?!api|admin|_next|.*\\..*).*)'] } // inline literal
* export const config = { matcher: ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)'] } // inline literal
*/
export function createProxy(
config: I18nConfig,
+4 -1
View File
@@ -164,5 +164,8 @@ export function createLocaleMiddleware({
/**
* Default Next.js middleware matcher: run on everything except API routes, the
* admin panel, Next internals, and files with an extension (static assets).
* `api`, `admin` and `_next` are skipped only as a WHOLE first segment (`/api`, `/api/…`): before 1.17.1 the
* lookahead did not end at "/", so `/administracja` or `/apis` skipped the proxy too (no locale redirect, no
* proxy CSP). The doctor's `proxy-matcher` rule reports the old literal.
*/
export const DEFAULT_MIDDLEWARE_MATCHER = ['/((?!api|admin|_next|.*\\..*).*)']
export const DEFAULT_MIDDLEWARE_MATCHER = ['/((?!(?:api|admin|_next)(?:/|$)|.*\\..*).*)']
+9 -3
View File
@@ -4,7 +4,7 @@
* (`pnpm build:starter`); a checkout of the repo can read `reference/` directly instead.
*/
import { execFileSync } from 'node:child_process'
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
import { existsSync, lstatSync, readdirSync, readFileSync } from 'node:fs'
import { join, relative, sep } from 'node:path'
import { gunzipSync, gzipSync } from 'node:zlib'
@@ -32,7 +32,8 @@ function walk(dir: string, root: string, out: string[]) {
const rel = relative(root, full).split(sep).join('/')
// never descend into installed or built trees
if (name === 'node_modules' || name === '.next' || name === '.git') {continue}
if (statSync(full).isDirectory()) {walk(full, root, out)}
// lstat: a link is listed as itself (and refused below), never followed into its target
if (lstatSync(full).isDirectory()) {walk(full, root, out)}
else {out.push(rel)}
}
}
@@ -42,7 +43,7 @@ function listFiles(dir: string): string[] {
try {
const out = execFileSync('git', ['ls-files', '-z', '--cached', '--', '.'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
const tracked = out.split('\0').filter(Boolean)
if (tracked.length) {return tracked.filter((path) => existsSync(join(dir, path)))}
if (tracked.length) {return tracked.filter((path) => existsSync(join(dir, path)) || lstatSync(join(dir, path), { throwIfNoEntry: false })?.isSymbolicLink())}
} catch {
// not a Git checkout (e.g. an unpacked tarball) — fall back to the folder
}
@@ -70,6 +71,11 @@ export function collectBundle(referenceDir: string): StarterBundle {
if (path === MANIFEST || path === LOCKFILE) {continue}
const role = fileRole(path, manifest)
if (role === 'drop') {continue}
// A link would be read through: its TARGET (a key, another project's .env) would ship in the published bundle.
if (lstatSync(join(referenceDir, path)).isSymbolicLink()) {
problems.push(`${path}: symbolic link — commit the file itself, or drop it in the manifest`)
continue
}
const content = readFileSync(join(referenceDir, path))
if (!isText(content)) {
problems.push(`${path}: binary file — drop it in the manifest`)
+18 -3
View File
@@ -5,7 +5,7 @@
import { spawnSync } from 'node:child_process'
import { createHash, randomBytes } from 'node:crypto'
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, join, relative, resolve } from 'node:path'
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
import { domainToASCII, fileURLToPath } from 'node:url'
import type { SiteContext } from './generate.js'
@@ -118,7 +118,17 @@ function run(log: Log, cwd: string, command: string, args: string[], env: Record
return result.status === 0
}
function writeFiles(dir: string, files: Record<string, string>) {
/**
* The new site's files, each under `dir`. A path that is absolute or climbs out with `..` stops the run before
* anything is written (the bundle is built from this repository's tracked files, so none does; a damaged or
* altered bundle must not write outside the new folder).
*/
export function writeFiles(dir: string, files: Record<string, string>) {
const outside = Object.keys(files).filter((path) => {
const target = resolve(dir, path)
return isAbsolute(path) || (target !== dir && !target.startsWith(`${resolve(dir)}${sep}`))
})
if (outside.length) {throw new Error(`the starter bundle names files outside the new folder: ${outside.join(', ')} — nothing was written`)}
for (const [path, content] of Object.entries(files)) {
const target = join(dir, path)
mkdirSync(dirname(target), { recursive: true })
@@ -208,7 +218,12 @@ export async function runCreateCli(args: string[], log: Log = (line) => process.
return 0
}
writeFiles(dir, files)
try {
writeFiles(dir, files)
} catch (error) {
log(`iapl create: ${(error as Error).message}`)
return 1
}
writeFileSync(join(dir, '.env'), localEnv(files['.env.example'] ?? ''))
log(`Wrote ${Object.keys(files).length} files to ${relative(cwd, dir) || '.'}`)