@socketsecurity/mcp 0.0.14 → 0.0.15

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 +25 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -235,15 +235,29 @@ 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 isLocalhostHost = host === `localhost:${port}` ||
253
+ host === `127.0.0.1:${port}` ||
254
+ host === 'localhost' ||
255
+ host === '127.0.0.1';
256
+ const isValidOrigin = origin
257
+ ? (isLocalhostOrigin(origin) || allowedOrigins.includes(origin))
258
+ : isLocalhostHost;
245
259
  if (!isValidOrigin) {
246
- logger.warn(`Rejected request from invalid origin: ${origin}`);
260
+ logger.warn(`Rejected request from invalid origin: ${origin || 'missing'} (host: ${host})`);
247
261
  res.writeHead(403, { 'Content-Type': 'application/json' });
248
262
  res.end(JSON.stringify({
249
263
  jsonrpc: '2.0',
@@ -252,9 +266,11 @@ if (useHttp) {
252
266
  }));
253
267
  return;
254
268
  }
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');
269
+ if (origin) {
270
+ res.setHeader('Access-Control-Allow-Origin', origin);
271
+ res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
272
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Accept');
273
+ }
258
274
  if (req.method === 'OPTIONS') {
259
275
  res.writeHead(200);
260
276
  res.end();
@@ -268,6 +284,8 @@ if (useHttp) {
268
284
  try {
269
285
  const jsonData = JSON.parse(body);
270
286
  if (jsonData && jsonData.method === 'initialize') {
287
+ const clientInfo = jsonData.params?.clientInfo;
288
+ logger.info(`Client connected: ${clientInfo?.name || 'unknown'} v${clientInfo?.version || 'unknown'} from ${origin || host}`);
271
289
  if (httpTransport) {
272
290
  try {
273
291
  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.15",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {