Skip to content

Commit 5146c23

Browse files
Geoff Smithclaude
andcommitted
security: add CSP, URL scheme validation, and promptId sanitization
- Add Content-Security-Policy meta tag restricting scripts, images, and connections to self, ComfyUI localhost, and Tailscale origins - Validate URL scheme in setServerUrl() to reject non-http(s) protocols - Sanitize promptId with encodeURIComponent in /history/ URL path Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent afb736c commit 5146c23

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎index.html‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta http-equiv="Content-Security-Policy" content="
8+
default-src 'self';
9+
script-src 'self';
10+
style-src 'self' 'unsafe-inline';
11+
img-src 'self' blob: data: http://127.0.0.1:8188 https://*.ts.net;
12+
connect-src 'self' http://127.0.0.1:8188 ws://127.0.0.1:8188 https://*.ts.net wss://*.ts.net;
13+
font-src 'self';
14+
object-src 'none';
15+
base-uri 'self';
16+
" />
717
<title>ComfyUI Web Interface</title>
818
</head>
919
<body>

‎src/services/comfyui-api.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function queuePrompt(workflow, clientId) {
5151
*/
5252
export async function getHistory(promptId) {
5353
try {
54-
const response = await fetch(`${getApiBase()}/history/${promptId}`);
54+
const response = await fetch(`${getApiBase()}/history/${encodeURIComponent(promptId)}`);
5555

5656
if (!response.ok) {
5757
throw new Error(`HTTP error! status: ${response.status}`);

‎src/utils/constants.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export function getServerUrl() {
2121

2222
export function setServerUrl(url) {
2323
const normalized = normalizeUrl(url);
24+
if (!/^https?:\/\//.test(normalized)) {
25+
throw new Error('Server URL must use http:// or https:// scheme');
26+
}
2427
if (normalized === DEFAULT_SERVER) {
2528
localStorage.removeItem(LS_KEY);
2629
} else {

0 commit comments

Comments
 (0)