@self-review/core 1.44.0 → 1.45.0

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.
package/dist/index.cjs CHANGED
@@ -428,7 +428,7 @@ async function runGitDiffAsync(args, cwd) {
428
428
  }
429
429
  }
430
430
  async function readGitBlobAsync(repoPath, spec) {
431
- return await new Promise((resolve6, reject) => {
431
+ return await new Promise((resolve7, reject) => {
432
432
  (0, import_child_process.execFile)(
433
433
  "git",
434
434
  ["-C", repoPath, "show", spec],
@@ -437,7 +437,7 @@ async function readGitBlobAsync(repoPath, spec) {
437
437
  if (error) {
438
438
  reject(error);
439
439
  } else {
440
- resolve6(stdout);
440
+ resolve7(stdout);
441
441
  }
442
442
  }
443
443
  );
@@ -1190,18 +1190,25 @@ function extFromMediaType(mediaType) {
1190
1190
  };
1191
1191
  return map[mediaType] || "png";
1192
1192
  }
1193
+ function assetNameComponent(idPrefix) {
1194
+ return String(idPrefix ?? "").replace(/[^A-Za-z0-9_-]/g, "_");
1195
+ }
1193
1196
  function persistAttachments(attachments, idPrefix, assetDir, onWrite) {
1194
1197
  if (!attachments?.length) return attachments;
1195
1198
  return attachments.map((att, index) => {
1196
1199
  if (!att.data) return att;
1197
1200
  onWrite();
1198
1201
  const ext = extFromMediaType(att.mediaType);
1199
- const fileName = `${idPrefix}-${index}.${ext}`;
1202
+ const fileName = `${assetNameComponent(idPrefix)}-${index}.${ext}`;
1200
1203
  const relativePath = `.self-review-assets/${fileName}`;
1204
+ const target = path.join(assetDir, fileName);
1205
+ if (path.dirname(path.resolve(target)) !== path.resolve(assetDir)) {
1206
+ throw new Error(`Refusing to write an attachment outside ${assetDir}: ${fileName}`);
1207
+ }
1201
1208
  if (!fs.existsSync(assetDir)) {
1202
1209
  fs.mkdirSync(assetDir, { recursive: true });
1203
1210
  }
1204
- fs.writeFileSync(path.join(assetDir, fileName), Buffer.from(att.data));
1211
+ fs.writeFileSync(target, Buffer.from(att.data));
1205
1212
  return { ...att, fileName: relativePath, data: void 0 };
1206
1213
  });
1207
1214
  }
@@ -2820,14 +2827,14 @@ init_git();
2820
2827
  var LOCAL_BASE_REF = "refs/self-review/base";
2821
2828
  var LOCAL_HEAD_REF = "refs/self-review/head";
2822
2829
  var AUTH_HINT = "Hint: if this repository is private or requires authentication, run `gh auth setup-git` (GitHub) or `glab auth git-credential` (GitLab) to wire your CLI credentials into git.";
2823
- var defaultGitRunner = (command, args) => new Promise((resolve6, reject) => {
2830
+ var defaultGitRunner = (command, args) => new Promise((resolve7, reject) => {
2824
2831
  (0, import_child_process3.execFile)(command, args, { maxBuffer: 50 * 1024 * 1024 }, (error, stdout, stderr) => {
2825
2832
  const spawnCode = error?.code;
2826
2833
  if (error && typeof spawnCode === "string") {
2827
2834
  reject(error);
2828
2835
  return;
2829
2836
  }
2830
- resolve6({
2837
+ resolve7({
2831
2838
  stdout: stdout ?? "",
2832
2839
  stderr: stderr ?? "",
2833
2840
  exitCode: error ? typeof spawnCode === "number" ? spawnCode : 1 : 0