mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 00:30:21 +00:00
fix(diffs): harden viewer security and docs
This commit is contained in:
@@ -11,6 +11,8 @@ import type {
|
||||
import { VIEWER_LOADER_PATH } from "./viewer-assets.js";
|
||||
|
||||
const DEFAULT_FILE_NAME = "diff.txt";
|
||||
const MAX_PATCH_FILE_COUNT = 128;
|
||||
const MAX_PATCH_TOTAL_LINES = 120_000;
|
||||
|
||||
function escapeCssString(value: string): string {
|
||||
return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
||||
@@ -344,6 +346,17 @@ async function renderPatchDiff(
|
||||
if (files.length === 0) {
|
||||
throw new Error("Patch input did not contain any file diffs.");
|
||||
}
|
||||
if (files.length > MAX_PATCH_FILE_COUNT) {
|
||||
throw new Error(`Patch input contains too many files (max ${MAX_PATCH_FILE_COUNT}).`);
|
||||
}
|
||||
const totalLines = files.reduce((sum, fileDiff) => {
|
||||
const splitLines = Number.isFinite(fileDiff.splitLineCount) ? fileDiff.splitLineCount : 0;
|
||||
const unifiedLines = Number.isFinite(fileDiff.unifiedLineCount) ? fileDiff.unifiedLineCount : 0;
|
||||
return sum + Math.max(splitLines, unifiedLines, 0);
|
||||
}, 0);
|
||||
if (totalLines > MAX_PATCH_TOTAL_LINES) {
|
||||
throw new Error(`Patch input is too large to render (max ${MAX_PATCH_TOTAL_LINES} lines).`);
|
||||
}
|
||||
|
||||
const viewerPayloadOptions = buildDiffOptions(options);
|
||||
const imagePayloadOptions = buildDiffOptions(buildImageRenderOptions(options));
|
||||
|
||||
Reference in New Issue
Block a user