Security: Reject cross-origin connections to daemon and stream server (#274)

This commit is contained in:
Chris Tate
2026-01-26 00:42:00 -06:00
committed by GitHub
parent fcee8f70d1
commit f862e2f7df
3 changed files with 68 additions and 1 deletions
+13
View File
@@ -196,10 +196,23 @@ export async function startDaemon(options?: { streamPort?: number }): Promise<vo
const server = net.createServer((socket) => {
let buffer = '';
let httpChecked = false;
socket.on('data', async (data) => {
buffer += data.toString();
// Security: Detect and reject HTTP requests to prevent cross-origin attacks.
// Browsers using fetch() must send HTTP headers (e.g., "POST / HTTP/1.1"),
// while legitimate clients send raw JSON starting with "{".
if (!httpChecked) {
httpChecked = true;
const trimmed = buffer.trimStart();
if (/^(GET|POST|PUT|DELETE|HEAD|OPTIONS|PATCH|CONNECT|TRACE)\s/i.test(trimmed)) {
socket.destroy();
return;
}
}
// Process complete lines
while (buffer.includes('\n')) {
const newlineIdx = buffer.indexOf('\n');