@socketsecurity/mcp 0.0.14 → 0.0.16

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.
Files changed (2) hide show
  1. package/index.js +27 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -235,15 +235,31 @@ if (useHttp) {
235
235
  return;
236
236
  }
237
237
  const origin = req.headers.origin;
238
+ const isLocalhostOrigin = (originUrl) => {
239
+ try {
240
+ const url = new URL(originUrl);
241
+ return url.hostname === 'localhost' || url.hostname === '127.0.0.1';
242
+ }
243
+ catch {
244
+ return false;
245
+ }
246
+ };
238
247
  const allowedOrigins = [
239
- 'http://localhost:3000',
240
- 'http://127.0.0.1:3000',
241
248
  'https://mcp.socket.dev',
242
249
  'https://mcp.socket-staging.dev'
243
250
  ];
244
- const isValidOrigin = origin && allowedOrigins.includes(origin);
251
+ const host = req.headers.host || '';
252
+ const allowedHosts = allowedOrigins.map(o => new URL(o).hostname);
253
+ const isAllowedHost = host === `localhost:${port}` ||
254
+ host === `127.0.0.1:${port}` ||
255
+ host === 'localhost' ||
256
+ host === '127.0.0.1' ||
257
+ allowedHosts.includes(host);
258
+ const isValidOrigin = origin
259
+ ? (isLocalhostOrigin(origin) || allowedOrigins.includes(origin))
260
+ : isAllowedHost;
245
261
  if (!isValidOrigin) {
246
- logger.warn(`Rejected request from invalid origin: ${origin}`);
262
+ logger.warn(`Rejected request from invalid origin: ${origin || 'missing'} (host: ${host})`);
247
263
  res.writeHead(403, { 'Content-Type': 'application/json' });
248
264
  res.end(JSON.stringify({
249
265
  jsonrpc: '2.0',
@@ -252,9 +268,11 @@ if (useHttp) {
252
268
  }));
253
269
  return;
254
270
  }
255
- res.setHeader('Access-Control-Allow-Origin', origin);
256
- res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
257
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept');
271
+ if (origin) {
272
+ res.setHeader('Access-Control-Allow-Origin', origin);
273
+ res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
274
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept');
275
+ }
258
276
  if (req.method === 'OPTIONS') {
259
277
  res.writeHead(200);
260
278
  res.end();
@@ -268,6 +286,8 @@ if (useHttp) {
268
286
  try {
269
287
  const jsonData = JSON.parse(body);
270
288
  if (jsonData && jsonData.method === 'initialize') {
289
+ const clientInfo = jsonData.params?.clientInfo;
290
+ logger.info(`Client connected: ${clientInfo?.name || 'unknown'} v${clientInfo?.version || 'unknown'} from ${origin || host}`);
271
291
  if (httpTransport) {
272
292
  try {
273
293
  httpTransport.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/mcp",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {