fix(agent): recover stale runs and improve new-user OA delivery
Fix DEV logout cookie clearing, materialize selected MindSpace OA assets before agent runs, and recover zombie runs from synced workspace pages. Add client run wait timeout, harness retry limits, page-edit asset forwarding, and logout/john2 scenario tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+54
-12
@@ -1,10 +1,16 @@
|
||||
const SCRIPT_PATTERNS = [
|
||||
/<script\b/i,
|
||||
/javascript:/i,
|
||||
/\bon\w+\s*=/i,
|
||||
/<iframe\b/i,
|
||||
/<object\b/i,
|
||||
/<embed\b/i,
|
||||
const BLOCKED_ACTIVE_PATTERNS = [
|
||||
{ type: 'javascript_url', pattern: /javascript:/i },
|
||||
{ type: 'inline_event_handler', pattern: /\bon\w+\s*=/i },
|
||||
{ type: 'embedded_active_content', pattern: /<iframe\b|<object\b|<embed\b/i },
|
||||
];
|
||||
|
||||
const SCRIPT_TAG_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
||||
const SCRIPT_SRC_PATTERN = /\bsrc\s*=\s*(['"])([^'"]+)\1/i;
|
||||
const TRUSTED_SCRIPT_SRC_PATTERNS = [
|
||||
/^\/assets\/chart\.umd\.min\.js(?:[?#].*)?$/i,
|
||||
/^https:\/\/cdn\.jsdelivr\.net\/npm\/chart\.js(?:@[^/]+)?\/dist\/chart\.(?:umd\.)?min\.js(?:[?#].*)?$/i,
|
||||
/^https:\/\/cdnjs\.cloudflare\.com\/ajax\/libs\/Chart\.js\/[^/]+\/chart\.(?:umd\.)?min\.js(?:[?#].*)?$/i,
|
||||
/^https:\/\/unpkg\.com\/chart\.js(?:@[^/]+)?\/dist\/chart\.(?:umd\.)?min\.js(?:[?#].*)?$/i,
|
||||
];
|
||||
|
||||
const MAX_ZIP_COMPRESSION_RATIO = 100;
|
||||
@@ -19,17 +25,53 @@ function isZipContainer(mimeType) {
|
||||
);
|
||||
}
|
||||
|
||||
function scanTextContent(buffer) {
|
||||
function isTrustedScriptSrc(src) {
|
||||
const normalized = String(src ?? '').trim().replace(/^\/\//, 'https://');
|
||||
return TRUSTED_SCRIPT_SRC_PATTERNS.some((pattern) => pattern.test(normalized));
|
||||
}
|
||||
|
||||
function scanScriptTags(sample, { htmlActiveContentPolicy }) {
|
||||
const scripts = [...sample.matchAll(SCRIPT_TAG_PATTERN)];
|
||||
if (!scripts.length) return null;
|
||||
if (htmlActiveContentPolicy !== 'sandbox_warn') {
|
||||
return {
|
||||
scanStatus: 'blocked',
|
||||
riskLevel: 'high',
|
||||
findings: ['text_active_content'],
|
||||
};
|
||||
}
|
||||
const untrusted = scripts.some((match) => {
|
||||
const attrs = match[1] ?? '';
|
||||
const src = attrs.match(SCRIPT_SRC_PATTERN)?.[2] ?? null;
|
||||
return src ? !isTrustedScriptSrc(src) : false;
|
||||
});
|
||||
if (untrusted) {
|
||||
return {
|
||||
scanStatus: 'blocked',
|
||||
riskLevel: 'high',
|
||||
findings: ['text_active_content'],
|
||||
};
|
||||
}
|
||||
return {
|
||||
scanStatus: 'warned',
|
||||
riskLevel: 'medium',
|
||||
findings: ['trusted_html_active_content'],
|
||||
};
|
||||
}
|
||||
|
||||
function scanTextContent(buffer, options = {}) {
|
||||
const sample = buffer.subarray(0, Math.min(buffer.length, 256 * 1024)).toString('utf8');
|
||||
for (const pattern of SCRIPT_PATTERNS) {
|
||||
for (const { type, pattern } of BLOCKED_ACTIVE_PATTERNS) {
|
||||
if (pattern.test(sample)) {
|
||||
return {
|
||||
scanStatus: 'blocked',
|
||||
riskLevel: 'high',
|
||||
findings: ['text_active_content'],
|
||||
findings: [type],
|
||||
};
|
||||
}
|
||||
}
|
||||
const scriptFinding = scanScriptTags(sample, options);
|
||||
if (scriptFinding) return scriptFinding;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -72,7 +114,7 @@ function scanZipStructure(buffer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function runBasicFileScan(buffer, { filename, mimeType }) {
|
||||
export function runBasicFileScan(buffer, { filename, mimeType, htmlActiveContentPolicy = 'block' }) {
|
||||
if (!Buffer.isBuffer(buffer) || buffer.length === 0) {
|
||||
return {
|
||||
scanStatus: 'blocked',
|
||||
@@ -82,7 +124,7 @@ export function runBasicFileScan(buffer, { filename, mimeType }) {
|
||||
}
|
||||
|
||||
if (mimeType.startsWith('text/') || mimeType === 'application/pdf') {
|
||||
const textFinding = scanTextContent(buffer);
|
||||
const textFinding = scanTextContent(buffer, { filename, mimeType, htmlActiveContentPolicy });
|
||||
if (textFinding) return textFinding;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user