@hyperframes/studio-server 0.8.84 → 0.8.86

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.js CHANGED
@@ -2274,6 +2274,8 @@ async function processUploadedFiles(formData, targetDir, projectDir) {
2274
2274
  }
2275
2275
  return { uploaded, skipped, invalid, unchecked };
2276
2276
  }
2277
+ var MAX_TEXT_READ_BYTES = 32 * 1024 * 1024;
2278
+ var GIT_BINARY_SNIFF_BYTES = 8e3;
2277
2279
  function registerFileRoutes(api, adapter) {
2278
2280
  api.get("/projects/:id/files/*", async (c) => {
2279
2281
  const res = await resolveProjectFile(c, adapter);
@@ -2288,12 +2290,19 @@ function registerFileRoutes(api, adapter) {
2288
2290
  return c.json({ error: "not found" }, 404);
2289
2291
  }
2290
2292
  try {
2291
- if (!fstatSync(fd).isFile()) {
2293
+ const stat2 = fstatSync(fd);
2294
+ if (!stat2.isFile()) {
2292
2295
  return c.json({ error: "not found", why: "not_a_file" }, 404);
2293
2296
  }
2297
+ if (stat2.size > MAX_TEXT_READ_BYTES) {
2298
+ return c.json({ error: "too large to read as text", why: "too_large" }, 413);
2299
+ }
2294
2300
  const content = readFileSync4(fd);
2295
2301
  const version = fileContentVersion(content);
2296
2302
  c.header("ETag", version);
2303
+ if (content.subarray(0, GIT_BINARY_SNIFF_BYTES).includes(0)) {
2304
+ return c.json({ error: "not a text file", why: "binary", version }, 415);
2305
+ }
2297
2306
  return c.json({
2298
2307
  filename: res.filePath,
2299
2308
  content: content.toString("utf-8"),