mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-21 12:18:24 +08:00
Merge remote-tracking branch 'origin/main' into garrytan/sidebar-css-inspector
# Conflicts: # browse/src/server.ts # browse/src/sidebar-agent.ts
This commit is contained in:
@@ -42,6 +42,21 @@ export const META_COMMANDS = new Set([
|
||||
|
||||
export const ALL_COMMANDS = new Set([...READ_COMMANDS, ...WRITE_COMMANDS, ...META_COMMANDS]);
|
||||
|
||||
/** Commands that return untrusted third-party page content */
|
||||
export const PAGE_CONTENT_COMMANDS = new Set([
|
||||
'text', 'html', 'links', 'forms', 'accessibility',
|
||||
'console', 'dialog',
|
||||
]);
|
||||
|
||||
/** Wrap output from untrusted-content commands with trust boundary markers */
|
||||
export function wrapUntrustedContent(result: string, url: string): string {
|
||||
// Sanitize URL: remove newlines to prevent marker injection via history.pushState
|
||||
const safeUrl = url.replace(/[\n\r]/g, '').slice(0, 200);
|
||||
// Escape marker strings in content to prevent boundary escape attacks
|
||||
const safeResult = result.replace(/--- (BEGIN|END) UNTRUSTED EXTERNAL CONTENT/g, '--- $1 UNTRUSTED EXTERNAL C\u200BONTENT');
|
||||
return `--- BEGIN UNTRUSTED EXTERNAL CONTENT (source: ${safeUrl}) ---\n${safeResult}\n--- END UNTRUSTED EXTERNAL CONTENT ---`;
|
||||
}
|
||||
|
||||
export const COMMAND_DESCRIPTIONS: Record<string, { category: string; description: string; usage?: string }> = {
|
||||
// Navigation
|
||||
'goto': { category: 'Navigation', description: 'Navigate to URL', usage: 'goto <url>' },
|
||||
|
||||
Reference in New Issue
Block a user