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:
co-authored by
Claude Opus 5.5
parent
e821d52d19
commit
498b3dbf38
+49
-2
@@ -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 })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user