Skip to content

See how your app actually fits together. An interactive, plain-English map of your codebase, drawn by Claude or Codex.

Server: answer only to 127.0.0.1 and localhost at its own port

Hayden Smith4573b5aa6ca1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 749fb36..bc5bfb3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## Unreleased
+
+- **The map's server answers only to this computer's own addresses:** it refuses requests under any other host name, so a website that points its domain at 127.0.0.1 (DNS rebinding) can't load the map, read its token and ask questions about your code.
+
## 0.3.1 (2026-10-30)
- **Asking on a map works again on Windows with the current Claude Code install:** the map's server found only the shell shim of an npm install and failed with `spawn ...\claude ENOENT`; it now finds the real `claude.exe` inside the package. Reported and fixed by @menachem-kurkus in #20 and #21.
diff --git a/docs/privacy-and-security.md b/docs/privacy-and-security.md
index bcb2406..24406f1 100644
--- a/docs/privacy-and-security.md
+++ b/docs/privacy-and-security.md
@@ -22,6 +22,7 @@ The layout engine ([elkjs](https://github.com/kieler/elkjs) 0.9.3, EPL-2.0) and
- It listens on `127.0.0.1` only, so other machines on your network can't reach it.
- Every start creates a random token, which only the map page it serves receives. Asking questions and saving flows require that token, and those requests are refused when they come from another website.
+- It answers only to `127.0.0.1` and `localhost` at its own port, so a website that points its own domain at your computer (DNS rebinding) can't load the map or its token.
- Questions run Claude with **read-only** tools: reading files, searching, and the map's own lookup script. It can't edit files or run other commands.
- With Codex, questions run in Codex's **read-only** sandbox: it can read and search, but not write files.
- On a blueprint (a map planned from a PRD), **Change** requests run the same read-only way. The agent replies with the updated plan, and the server itself writes only `floorplan/plan.json`, `floorplan/architecture.json` and `floorplan/recent-work.json`, after checking them, keeping the old copies for Undo.
diff --git a/skills/floorplan/assets/serve.mjs b/skills/floorplan/assets/serve.mjs
index 741ff23..dd45e69 100644
--- a/skills/floorplan/assets/serve.mjs
+++ b/skills/floorplan/assets/serve.mjs
@@ -445,6 +445,9 @@ function undoChange() {
// ---------- http ----------
const server = http.createServer((req, res) => {
+ // only this machine's own names: a website that points its domain at 127.0.0.1 (DNS rebinding) would
+ // otherwise count as the same origin as the map, and could read its token from the page
+ if (![`127.0.0.1:${port}`, `localhost:${port}`].includes(String(req.headers.host || '').toLowerCase())) { res.writeHead(403); return res.end('unknown host'); }
const url = new URL(req.url, `http://${req.headers.host}`);
const sameOrigin = !req.headers.origin || req.headers.origin === `http://${req.headers.host}`;
if (url.pathname.startsWith('/api/')) {
diff --git a/tests/serve.test.mjs b/tests/serve.test.mjs
index b3748a5..1c5aa10 100644
--- a/tests/serve.test.mjs
+++ b/tests/serve.test.mjs
@@ -3,6 +3,7 @@
import { test, before, after } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
+import http from 'node:http';
import path from 'node:path';
import { spawn } from 'node:child_process';
import { shopApp, scanAndBuild, cleanup } from './helpers.mjs';
@@ -51,6 +52,21 @@ test('API calls with the token from another website are refused', async () => {
assert.equal(r.status, 403);
});
+/** A request to the server under another host name, as a site that rebinds its domain to 127.0.0.1 would send. */
+const asHost = (host, p) => new Promise((resolve, reject) => {
+ const u = new URL(base + p);
+ http.get({ hostname: u.hostname, port: u.port, path: u.pathname, headers: { host, 'x-floorplan-token': token } }, (r) => { r.resume(); resolve(r.statusCode); }).on('error', reject);
+});
+
+test('requests under any other host name are refused, page included (DNS rebinding)', async () => {
+ const port = new URL(base).port;
+ assert.equal(await asHost(`evil.example:${port}`, '/'), 403);
+ assert.equal(await asHost(`evil.example:${port}`, '/api/flows'), 403);
+ assert.equal(await asHost('127.0.0.1:1', '/'), 403);
+ assert.equal(await asHost(`localhost:${port}`, '/'), 200);
+ assert.equal(await asHost(`127.0.0.1:${port}`, '/api/flows'), 200);
+});
+
test('API calls with the token from the map itself work', async () => {
const r = await api('/api/flows', { headers: { 'x-floorplan-token': token } });
assert.equal(r.status, 200);