@rig-c/review 1.16.5 → 1.16.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/parts-view.ts +23 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/review",
3
- "version": "1.16.5",
3
+ "version": "1.16.6",
4
4
  "type": "module",
5
5
  "description": "Local human rig inspection and structured feedback export",
6
6
  "license": "MIT",
package/src/parts-view.ts CHANGED
@@ -99,7 +99,7 @@ const refuse = (code: string, message: string): never => { throw new Error(`${co
99
99
  export async function insideRoot(root: string, path: string, code: string, what: string): Promise<string> {
100
100
  const realRoot = await realpath(root), real = await realpath(path);
101
101
  const rel = relative(realRoot, real);
102
- if (!rel || rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) refuse(code, `${what} resolves outside ${basename(realRoot)}/ (symlinks may not escape the package)`);
102
+ if (!rel || rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) refuse(code, `${what} resolves outside ${basename(realRoot)}/`);
103
103
  return real;
104
104
  }
105
105
 
@@ -128,6 +128,21 @@ function relativeTo(dir: string, abs: string): string {
128
128
  return sep === '/' ? rel : rel.split(sep).join('/');
129
129
  }
130
130
 
131
+ /** Match canonical input paths, resolving only the destination's parent. Missing
132
+ * directories retain their suffix; the output leaf is never followed through a symlink. */
133
+ async function verdictDestination(path: string): Promise<string> {
134
+ const abs = resolve(path), suffix = [basename(abs)];
135
+ let parent = dirname(abs);
136
+ for (;;) {
137
+ try { return join(await realpath(parent), ...suffix); }
138
+ catch (error) {
139
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT' || dirname(parent) === parent) throw error;
140
+ suffix.unshift(basename(parent));
141
+ parent = dirname(parent);
142
+ }
143
+ }
144
+ }
145
+
131
146
  /** Faint islands (rig-parts #326) from `mesh_report.json` rows, on the parts the view holds. */
132
147
  export function meshReportFlags(rows: unknown, names: ReadonlySet<string>): ProducerFlag[] {
133
148
  if (!Array.isArray(rows)) refuse('PARTS_FLAGS_MALFORMED', 'mesh_report.json is not an array of rows');
@@ -234,7 +249,7 @@ async function producerFlags(rigDir: string | null, buildRoot: string | null, na
234
249
  const flags: ProducerFlag[] = [], readings: ProducerFlag[] = [], files: LocalFile[] = [], notes: string[] = [];
235
250
  // A discovered file must resolve inside the directory it was discovered in; a path given on the command line is the user's own choice.
236
251
  const pick = async (explicit: string | undefined, candidates: ([string, string] | null)[], what: string): Promise<string | null> => {
237
- if (explicit !== undefined) return resolve(explicit);
252
+ if (explicit !== undefined) return realpath(resolve(explicit));
238
253
  const found = candidates.find((c): c is [string, string] => !!c && existsSync(c[1]));
239
254
  return found ? insideRoot(found[0], found[1], 'PARTS_FLAGS_OUTSIDE', what) : null;
240
255
  };
@@ -352,8 +367,9 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
352
367
  paintingInRig={abs,declaredPath,bytes:bytes.length,sha256,width:png!.width,height:png!.height};files.push(paintingInRig);
353
368
  }
354
369
  let painting:PartsViewPackage['painting'];if(options.painting){
355
- const candidate=resolve(options.painting),rel=relative(resolve(root),candidate);if(!rel||rel==='..'||rel.startsWith('..'+sep)||isAbsolute(rel))refuse('PARTS_PAINTING_OUTSIDE','painting must be inside the parts package');
356
- let abs:string,bytes:Buffer;try{abs=await insideRoot(root,candidate,'PARTS_PAINTING_OUTSIDE','painting');packagePath(relative(root,abs).split(sep).join('/'),'painting');bytes=await readFile(abs);}catch(error){if(error instanceof Error&&error.message.startsWith('PARTS_PAINTING_OUTSIDE:'))throw error;refuse('PARTS_PAINTING_UNAVAILABLE','painting must be a readable portable package PNG');}
370
+ // Both paths are physical: a user-designated alias to an inside file is valid,
371
+ // while a link reaching outside is refused before any painting bytes are read.
372
+ let abs:string,bytes:Buffer;try{abs=await insideRoot(root,resolve(options.painting),'PARTS_PAINTING_OUTSIDE','painting');packagePath(relative(root,abs).split(sep).join('/'),'painting');bytes=await readFile(abs);}catch(error){if(error instanceof Error&&error.message.startsWith('PARTS_PAINTING_OUTSIDE:'))throw error;refuse('PARTS_PAINTING_UNAVAILABLE','painting must be a readable portable package PNG');}
357
373
  let png:PNG;try{png=PNG.sync.read(bytes!);}catch{refuse('PARTS_PAINTING_PNG','painting must be a valid PNG');}
358
374
  assertOriginalPaintingSize(png!.width,png!.height,rigSize,doc.scale_rig_per_source);
359
375
  const file={abs:abs!,bytes:bytes!.length,sha256:createHash('sha256').update(bytes!).digest('hex')};painting={...file,width:png!.width,height:png!.height};files.push(file);
@@ -362,9 +378,9 @@ async function loadPartsMode(root: string, options: PartsViewOptions): Promise<P
362
378
  const protectedPaths = [join(root, 'rig.json'), join(root, 'config.json'), join(root, 'review.json'), join(root, 'report.json')];
363
379
  if (basename(root) === 'rig') protectedPaths.push(...['parts.json', 'config.json', 'review.json', 'report.json'].map(name => join(dirname(root), name)));
364
380
  if (options.rig !== undefined) protectedPaths.push(resolve(options.rig));
365
- const verdictPath = options.verdict ? resolve(options.verdict) : join(root, PARTS_VERDICT_FILE);
381
+ const verdictPath = options.verdict ? await verdictDestination(options.verdict) : join(root, PARTS_VERDICT_FILE);
366
382
  await assertVerdictDestination({ files, flagFiles, protectedPaths, verdictPath });
367
- const rigPath = options.rig !== undefined ? resolve(options.rig) : existsSync(join(root, 'rig.json')) ? await insideRoot(root, join(root, 'rig.json'), 'PARTS_MESH_OUTSIDE', 'rig.json') : null;
383
+ const rigPath = options.rig !== undefined ? await realpath(resolve(options.rig)) : existsSync(join(root, 'rig.json')) ? await insideRoot(root, join(root, 'rig.json'), 'PARTS_MESH_OUTSIDE', 'rig.json') : null;
368
384
  if (rigPath) {
369
385
  const report = notes.includes('mesh_report.json') ? undefined : flagFiles[0];
370
386
  const rigBytes = await readFile(rigPath);
@@ -419,7 +435,7 @@ export async function loadPartsAtlas(p: ReviewPackage, options: PartsViewOptions
419
435
  protectedPaths.push(...['rig.json', 'config.json', 'report.json', 'review.json'].map(name => join(p.root, name)));
420
436
  if (p.handoff) protectedPaths.push(...p.handoff.record.files.map(file => resolve(p.root, file.path)));
421
437
  if (buildRoot) protectedPaths.push(...['parts.json', 'config.json', 'rig/rig.json', 'rig/parts.json'].map(name => join(buildRoot, name)));
422
- return { mode: 'atlas', root: p.root, title: p.manifest.title, rigSize: null, items, pages, flags, readings, files, flagFiles, flagNotes: notes, protectedPaths, verdictPath: options.verdict ? resolve(options.verdict) : join(dirname(modelAbs), PARTS_VERDICT_FILE), imagePaths: [], pagePaths };
438
+ return { mode: 'atlas', root: p.root, title: p.manifest.title, rigSize: null, items, pages, flags, readings, files, flagFiles, flagNotes: notes, protectedPaths, verdictPath: options.verdict ? await verdictDestination(options.verdict) : join(dirname(modelAbs), PARTS_VERDICT_FILE), imagePaths: [], pagePaths };
423
439
  }
424
440
 
425
441
  /**