red-design-mcp 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -11
- package/dist/a11y.js +20 -7
- package/dist/agents.js +24 -0
- package/dist/cli.js +108 -28
- package/dist/colorparse.js +277 -0
- package/dist/csp.js +242 -0
- package/dist/cssparse.js +163 -50
- package/dist/gateway.js +7 -0
- package/dist/htmlscan.js +159 -0
- package/dist/playbooks.js +9 -0
- package/dist/secrets.js +113 -0
- package/dist/security.js +271 -0
- package/dist/server.js +166 -44
- package/dist/toolsets.js +4 -3
- package/dist/vision.js +70 -13
- package/dist/web.js +213 -3
- package/package.json +9 -1
package/dist/web.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { lookup } from "node:dns/promises";
|
|
2
|
+
import { isIP } from "node:net";
|
|
1
3
|
export function assertHttp(url) {
|
|
2
4
|
let u;
|
|
3
5
|
try {
|
|
@@ -10,18 +12,225 @@ export function assertHttp(url) {
|
|
|
10
12
|
throw new Error("Only http(s) URLs are supported.");
|
|
11
13
|
return u;
|
|
12
14
|
}
|
|
15
|
+
function classifyV4([a, b, c]) {
|
|
16
|
+
if (a === 0)
|
|
17
|
+
return "reserved";
|
|
18
|
+
if (a === 10)
|
|
19
|
+
return "private";
|
|
20
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
21
|
+
return "private"; // carrier-grade NAT
|
|
22
|
+
if (a === 127)
|
|
23
|
+
return "loopback";
|
|
24
|
+
if (a === 169 && b === 254)
|
|
25
|
+
return "link-local"; // includes cloud metadata 169.254.169.254
|
|
26
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
27
|
+
return "private";
|
|
28
|
+
if (a === 192 && b === 0 && (c === 0 || c === 2))
|
|
29
|
+
return "reserved";
|
|
30
|
+
if (a === 192 && b === 168)
|
|
31
|
+
return "private";
|
|
32
|
+
if (a === 198 && (b === 18 || b === 19))
|
|
33
|
+
return "reserved";
|
|
34
|
+
if (a === 198 && b === 51 && c === 100)
|
|
35
|
+
return "reserved";
|
|
36
|
+
if (a === 203 && b === 0 && c === 113)
|
|
37
|
+
return "reserved";
|
|
38
|
+
if (a >= 224)
|
|
39
|
+
return "reserved"; // multicast, reserved and broadcast
|
|
40
|
+
return "public";
|
|
41
|
+
}
|
|
42
|
+
function expandV6(ip) {
|
|
43
|
+
let s = ip;
|
|
44
|
+
const m = s.match(/^(.*:)(\d+\.\d+\.\d+\.\d+)$/);
|
|
45
|
+
if (m) {
|
|
46
|
+
const v4 = m[2].split(".").map(Number);
|
|
47
|
+
if (v4.length !== 4 || v4.some((n) => !(n >= 0 && n <= 255)))
|
|
48
|
+
return null;
|
|
49
|
+
s = `${m[1]}${((v4[0] << 8) | v4[1]).toString(16)}:${((v4[2] << 8) | v4[3]).toString(16)}`;
|
|
50
|
+
}
|
|
51
|
+
const parts = s.split("::");
|
|
52
|
+
if (parts.length > 2)
|
|
53
|
+
return null;
|
|
54
|
+
const head = parts[0] ? parts[0].split(":") : [];
|
|
55
|
+
const tail = parts.length === 2 && parts[1] ? parts[1].split(":") : [];
|
|
56
|
+
const fill = parts.length === 2 ? 8 - head.length - tail.length : 0;
|
|
57
|
+
if (fill < 0 || (parts.length === 1 && head.length !== 8))
|
|
58
|
+
return null;
|
|
59
|
+
const groups = [...head, ...Array(fill).fill("0"), ...tail].map((g) => parseInt(g, 16));
|
|
60
|
+
return groups.length === 8 && groups.every((n) => Number.isInteger(n) && n >= 0 && n <= 0xffff) ? groups : null;
|
|
61
|
+
}
|
|
62
|
+
function classifyV6(ip) {
|
|
63
|
+
const g = expandV6(ip);
|
|
64
|
+
if (!g)
|
|
65
|
+
return "reserved";
|
|
66
|
+
const zero = (from, to) => g.slice(from, to).every((x) => x === 0);
|
|
67
|
+
const v4 = (hi, lo) => classifyV4([hi >> 8, hi & 255, lo >> 8, lo & 255]);
|
|
68
|
+
if (zero(0, 8))
|
|
69
|
+
return "reserved"; // ::
|
|
70
|
+
if (zero(0, 7) && g[7] === 1)
|
|
71
|
+
return "loopback"; // ::1
|
|
72
|
+
if (zero(0, 5) && g[5] === 0xffff)
|
|
73
|
+
return v4(g[6], g[7]); // IPv4-mapped
|
|
74
|
+
if (g[0] === 0x64 && g[1] === 0xff9b && zero(2, 6))
|
|
75
|
+
return v4(g[6], g[7]); // NAT64
|
|
76
|
+
if (g[0] === 0x2002)
|
|
77
|
+
return v4(g[1], g[2]); // 6to4
|
|
78
|
+
if ((g[0] & 0xffc0) === 0xfe80)
|
|
79
|
+
return "link-local";
|
|
80
|
+
if ((g[0] & 0xfe00) === 0xfc00)
|
|
81
|
+
return "private"; // unique local
|
|
82
|
+
if ((g[0] & 0xff00) === 0xff00)
|
|
83
|
+
return "reserved"; // multicast
|
|
84
|
+
if (g[0] === 0x2001 && g[1] === 0x0db8)
|
|
85
|
+
return "reserved"; // documentation
|
|
86
|
+
return "public";
|
|
87
|
+
}
|
|
88
|
+
export function classifyIp(ip) {
|
|
89
|
+
const clean = ip.replace(/^\[|\]$/g, "").split("%")[0].toLowerCase();
|
|
90
|
+
const kind = isIP(clean);
|
|
91
|
+
if (kind === 4)
|
|
92
|
+
return classifyV4(clean.split(".").map(Number));
|
|
93
|
+
if (kind === 6)
|
|
94
|
+
return classifyV6(clean);
|
|
95
|
+
return "reserved";
|
|
96
|
+
}
|
|
97
|
+
const allowPrivate = () => /^(1|true|yes)$/i.test(process.env.RED_ALLOW_PRIVATE_URLS ?? "");
|
|
98
|
+
/**
|
|
99
|
+
* Accepts only http(s) URLs whose host resolves to public addresses. Loopback and private networks
|
|
100
|
+
* need RED_ALLOW_PRIVATE_URLS=1; link-local (cloud metadata) and reserved ranges are never allowed.
|
|
101
|
+
*/
|
|
102
|
+
export async function assertPublicUrl(raw) {
|
|
103
|
+
const u = assertHttp(raw);
|
|
104
|
+
const host = u.hostname.replace(/^\[|\]$/g, "");
|
|
105
|
+
let addrs;
|
|
106
|
+
if (isIP(host))
|
|
107
|
+
addrs = [host];
|
|
108
|
+
else {
|
|
109
|
+
try {
|
|
110
|
+
addrs = (await lookup(host, { all: true, verbatim: true })).map((a) => a.address);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
throw new Error(`Could not resolve "${host}".`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!addrs.length)
|
|
117
|
+
throw new Error(`Could not resolve "${host}".`);
|
|
118
|
+
for (const a of addrs) {
|
|
119
|
+
const c = classifyIp(a);
|
|
120
|
+
const local = c === "private" || c === "loopback";
|
|
121
|
+
if (c === "public" || (local && allowPrivate()))
|
|
122
|
+
continue;
|
|
123
|
+
throw new Error(`Blocked ${host} (${a}, ${c} address). ` +
|
|
124
|
+
(local
|
|
125
|
+
? "Private and local addresses are blocked by default so that a prompt cannot make this server probe your network. Set RED_ALLOW_PRIVATE_URLS=1 to allow them, for example to capture your own dev server."
|
|
126
|
+
: "This address range is never allowed."));
|
|
127
|
+
}
|
|
128
|
+
return u;
|
|
129
|
+
}
|
|
130
|
+
/** fetch() that validates the URL and every redirect hop before connecting, and records the hops. */
|
|
131
|
+
export async function fetchWithChain(url, init = {}, maxRedirects = 5) {
|
|
132
|
+
let current = url;
|
|
133
|
+
const chain = [];
|
|
134
|
+
for (let i = 0; i <= maxRedirects; i++) {
|
|
135
|
+
await assertPublicUrl(current);
|
|
136
|
+
const res = await fetch(current, { ...init, redirect: "manual" });
|
|
137
|
+
const loc = res.headers.get("location");
|
|
138
|
+
if (res.status >= 300 && res.status < 400 && loc) {
|
|
139
|
+
const next = new URL(loc, current).href;
|
|
140
|
+
chain.push({ url: current, status: res.status, location: next });
|
|
141
|
+
current = next;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
return { res, finalUrl: current, chain };
|
|
145
|
+
}
|
|
146
|
+
throw new Error("Too many redirects.");
|
|
147
|
+
}
|
|
148
|
+
/** fetch() that validates the URL and every redirect hop before connecting. */
|
|
149
|
+
export async function safeFetch(url, init = {}, maxRedirects = 5) {
|
|
150
|
+
return (await fetchWithChain(url, init, maxRedirects)).res;
|
|
151
|
+
}
|
|
152
|
+
/** Set-Cookie values as separate strings (fetch merges them in some runtimes). */
|
|
153
|
+
export function getSetCookies(h) {
|
|
154
|
+
const fn = h.getSetCookie;
|
|
155
|
+
if (typeof fn === "function")
|
|
156
|
+
return fn.call(h);
|
|
157
|
+
const raw = h.get("set-cookie");
|
|
158
|
+
return raw ? raw.split(/,(?=\s*[^;,\s=]+=)/) : [];
|
|
159
|
+
}
|
|
160
|
+
/** Add https:// when a bare domain is given. */
|
|
161
|
+
export const withScheme = (u) => (/^[a-z][a-z0-9+.-]*:/i.test(u.trim()) ? u.trim() : `https://${u.trim()}`);
|
|
162
|
+
/** One GET of a public page: headers, cookies, redirect chain and (for HTML) the markup. */
|
|
163
|
+
export async function fetchPage(url, timeoutMs = 15000) {
|
|
164
|
+
const requestedUrl = withScheme(url);
|
|
165
|
+
const ctrl = new AbortController();
|
|
166
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
167
|
+
try {
|
|
168
|
+
const { res, finalUrl, chain } = await fetchWithChain(requestedUrl, {
|
|
169
|
+
signal: ctrl.signal,
|
|
170
|
+
headers: { "user-agent": "Mozilla/5.0 (compatible; red-design-mcp)", accept: "text/html,application/xhtml+xml,*/*;q=0.8" },
|
|
171
|
+
});
|
|
172
|
+
const headers = {};
|
|
173
|
+
res.headers.forEach((v, k) => {
|
|
174
|
+
const key = k.toLowerCase();
|
|
175
|
+
if (key !== "set-cookie")
|
|
176
|
+
headers[key] = headers[key] ? `${headers[key]}, ${v}` : v;
|
|
177
|
+
});
|
|
178
|
+
const contentType = headers["content-type"] ?? "";
|
|
179
|
+
let body;
|
|
180
|
+
if (/html/i.test(contentType))
|
|
181
|
+
body = (await readBytes(res, 2_000_000)).toString("utf8");
|
|
182
|
+
else
|
|
183
|
+
await res.body?.cancel();
|
|
184
|
+
return { requestedUrl, finalUrl, status: res.status, chain, headers, setCookies: getSetCookies(res.headers), contentType, body };
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
if (err.name === "AbortError")
|
|
188
|
+
throw new Error(`Timed out after ${timeoutMs / 1000}s fetching ${requestedUrl}.`);
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** Read a response body without letting it grow past `max` bytes. */
|
|
196
|
+
export async function readBytes(res, max) {
|
|
197
|
+
const tooBig = () => new Error(`Response is larger than ${Math.round(max / 1_000_000)} MB.`);
|
|
198
|
+
const declared = Number(res.headers.get("content-length"));
|
|
199
|
+
if (declared && declared > max)
|
|
200
|
+
throw tooBig();
|
|
201
|
+
if (!res.body) {
|
|
202
|
+
const b = Buffer.from(await res.arrayBuffer());
|
|
203
|
+
if (b.length > max)
|
|
204
|
+
throw tooBig();
|
|
205
|
+
return b;
|
|
206
|
+
}
|
|
207
|
+
const reader = res.body.getReader();
|
|
208
|
+
const chunks = [];
|
|
209
|
+
let total = 0;
|
|
210
|
+
for (;;) {
|
|
211
|
+
const { done, value } = await reader.read();
|
|
212
|
+
if (done)
|
|
213
|
+
break;
|
|
214
|
+
total += value.length;
|
|
215
|
+
if (total > max) {
|
|
216
|
+
await reader.cancel();
|
|
217
|
+
throw tooBig();
|
|
218
|
+
}
|
|
219
|
+
chunks.push(Buffer.from(value));
|
|
220
|
+
}
|
|
221
|
+
return Buffer.concat(chunks);
|
|
222
|
+
}
|
|
13
223
|
export async function fetchText(url, timeoutMs = 12000) {
|
|
14
224
|
const ctrl = new AbortController();
|
|
15
225
|
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
16
226
|
try {
|
|
17
|
-
const res = await
|
|
227
|
+
const res = await safeFetch(url, {
|
|
18
228
|
signal: ctrl.signal,
|
|
19
|
-
redirect: "follow",
|
|
20
229
|
headers: { "user-agent": "Mozilla/5.0 (compatible; red-design-mcp)", accept: "text/html,text/css,*/*" },
|
|
21
230
|
});
|
|
22
231
|
if (!res.ok)
|
|
23
232
|
throw new Error(`${url} returned HTTP ${res.status}`);
|
|
24
|
-
return (await res
|
|
233
|
+
return (await readBytes(res, 2_000_000)).toString("utf8");
|
|
25
234
|
}
|
|
26
235
|
finally {
|
|
27
236
|
clearTimeout(timer);
|
|
@@ -49,6 +258,7 @@ export async function collectCss(pageUrl) {
|
|
|
49
258
|
/* ignore bad href */
|
|
50
259
|
}
|
|
51
260
|
}
|
|
261
|
+
// Each stylesheet URL goes through the same public-address check as the page itself.
|
|
52
262
|
const results = await Promise.allSettled([...new Set(hrefs)].slice(0, 8).map((h) => fetchText(h)));
|
|
53
263
|
let sheets = 0;
|
|
54
264
|
for (const r of results) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "red-design-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"mcpName": "io.github.stonefrozen096-collab/red-design-mcp",
|
|
4
5
|
"description": "Give your AI tools a designer's eye: analyze, recreate, reimagine, critique and audit any design. MCP server with one-command install for Claude Code, Codex, Cursor and Claude Desktop.",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"bin": {
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"color-palette",
|
|
32
33
|
"colorblind-safe",
|
|
33
34
|
"copilot",
|
|
35
|
+
"csp",
|
|
34
36
|
"css-linter",
|
|
35
37
|
"cursor",
|
|
36
38
|
"cursor-agents",
|
|
@@ -49,13 +51,19 @@
|
|
|
49
51
|
"gemini-cli",
|
|
50
52
|
"gradient",
|
|
51
53
|
"groq",
|
|
54
|
+
"html-audit",
|
|
52
55
|
"mcp",
|
|
53
56
|
"mcp-prompts",
|
|
54
57
|
"model-context-protocol",
|
|
55
58
|
"ollama",
|
|
56
59
|
"openai",
|
|
57
60
|
"openrouter",
|
|
61
|
+
"privacy",
|
|
62
|
+
"red-chex",
|
|
58
63
|
"screenshot",
|
|
64
|
+
"secret-scanning",
|
|
65
|
+
"security",
|
|
66
|
+
"security-headers",
|
|
59
67
|
"subagents",
|
|
60
68
|
"tool-discovery",
|
|
61
69
|
"typography",
|