@solongate/proxy 0.10.0 → 0.11.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.
Files changed (2) hide show
  1. package/dist/index.js +67 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -132,6 +132,7 @@ function parseArgs(argv) {
132
132
  let upstreamTransport;
133
133
  let port;
134
134
  let policyId;
135
+ let advancedDetection = true;
135
136
  let separatorIndex = args.indexOf("--");
136
137
  const flags = separatorIndex >= 0 ? args.slice(0, separatorIndex) : args;
137
138
  const upstreamArgs = separatorIndex >= 0 ? args.slice(separatorIndex + 1) : [];
@@ -174,6 +175,9 @@ function parseArgs(argv) {
174
175
  case "--id":
175
176
  policyId = flags[++i];
176
177
  break;
178
+ case "--no-advanced-detection":
179
+ advancedDetection = false;
180
+ break;
177
181
  }
178
182
  }
179
183
  if (apiKey && /^\$\{.+\}$/.test(apiKey)) {
@@ -222,7 +226,8 @@ function parseArgs(argv) {
222
226
  apiUrl: apiUrl ?? fileConfig.apiUrl,
223
227
  port: port ?? fileConfig.port,
224
228
  policyPath: resolvePolicyPath(cfgPolicySource) ?? void 0,
225
- policyId: policyId ?? fileConfig.policyId
229
+ policyId: policyId ?? fileConfig.policyId,
230
+ advancedDetection: advancedDetection ? { enabled: true } : void 0
226
231
  };
227
232
  }
228
233
  if (upstreamUrl) {
@@ -243,7 +248,8 @@ function parseArgs(argv) {
243
248
  apiUrl,
244
249
  port,
245
250
  policyPath: resolvedPolicyPath ?? void 0,
246
- policyId
251
+ policyId,
252
+ advancedDetection: advancedDetection ? { enabled: true } : void 0
247
253
  };
248
254
  }
249
255
  if (upstreamArgs.length === 0) {
@@ -268,7 +274,8 @@ function parseArgs(argv) {
268
274
  apiUrl,
269
275
  port,
270
276
  policyPath: resolvedPolicyPath ?? void 0,
271
- policyId
277
+ policyId,
278
+ advancedDetection: advancedDetection ? { enabled: true } : void 0
272
279
  };
273
280
  }
274
281
  function resolvePolicyPath(source) {
@@ -6171,6 +6178,61 @@ var SolonGateProxy = class {
6171
6178
  };
6172
6179
  }
6173
6180
  log2(`Tool call: ${name}`);
6181
+ let piResult;
6182
+ if (args && typeof args === "object") {
6183
+ const guardConfig = this.config.advancedDetection ? { ...DEFAULT_INPUT_GUARD_CONFIG2, advancedDetection: this.config.advancedDetection } : DEFAULT_INPUT_GUARD_CONFIG2;
6184
+ const argsCheck = this.config.advancedDetection ? await sanitizeInputAsync("tool.arguments", args, guardConfig) : sanitizeInput("tool.arguments", args);
6185
+ const hasPromptInjection = argsCheck.threats.some((t) => t.type === "PROMPT_INJECTION");
6186
+ if (hasPromptInjection) {
6187
+ const trustResult = "trustScore" in argsCheck ? argsCheck.trustScore : void 0;
6188
+ const matchedCategories = trustResult?.stages?.[0]?.details?.filter((d) => d.startsWith("matched:"))?.map((d) => d.replace("matched:", "")) ?? [];
6189
+ piResult = {
6190
+ detected: true,
6191
+ trustScore: trustResult?.trustScore ?? 0,
6192
+ blocked: true,
6193
+ matchedCategories,
6194
+ stageScores: {
6195
+ rules: trustResult?.stages?.[0]?.score ?? 0,
6196
+ embedding: trustResult?.stages?.[1]?.score ?? 0,
6197
+ classifier: trustResult?.stages?.[2]?.score ?? 0
6198
+ }
6199
+ };
6200
+ const threats = argsCheck.threats.map((t) => `${t.type}: ${t.description}`).join("; ");
6201
+ log2(`DENY tool call: ${name} \u2014 ${threats}`);
6202
+ if (this.config.apiKey && !this.config.apiKey.startsWith("sg_test_")) {
6203
+ const apiUrl = this.config.apiUrl ?? "https://api.solongate.com";
6204
+ sendAuditLog(this.config.apiKey, apiUrl, {
6205
+ tool: name,
6206
+ arguments: args ?? {},
6207
+ decision: "DENY",
6208
+ reason: `Prompt injection detected: ${threats}`,
6209
+ evaluationTimeMs: 0,
6210
+ promptInjection: piResult
6211
+ });
6212
+ }
6213
+ return {
6214
+ content: [{ type: "text", text: `Tool call blocked by input guard: ${threats}` }],
6215
+ isError: true
6216
+ };
6217
+ }
6218
+ if (this.config.advancedDetection && "trustScore" in argsCheck) {
6219
+ const trustResult = argsCheck.trustScore;
6220
+ if (trustResult) {
6221
+ const matchedCategories = trustResult.stages?.[0]?.details?.filter((d) => d.startsWith("matched:"))?.map((d) => d.replace("matched:", "")) ?? [];
6222
+ piResult = {
6223
+ detected: trustResult.rawScore > 0,
6224
+ trustScore: trustResult.trustScore,
6225
+ blocked: false,
6226
+ matchedCategories,
6227
+ stageScores: {
6228
+ rules: trustResult.stages?.[0]?.score ?? 0,
6229
+ embedding: trustResult.stages?.[1]?.score ?? 0,
6230
+ classifier: trustResult.stages?.[2]?.score ?? 0
6231
+ }
6232
+ };
6233
+ }
6234
+ }
6235
+ }
6174
6236
  const mutex = this.toolMutexes.get(name);
6175
6237
  try {
6176
6238
  await mutex.acquire(MUTEX_TIMEOUT_MS);
@@ -6219,7 +6281,8 @@ var SolonGateProxy = class {
6219
6281
  decision,
6220
6282
  reason,
6221
6283
  matchedRule,
6222
- evaluationTimeMs
6284
+ evaluationTimeMs,
6285
+ promptInjection: piResult
6223
6286
  });
6224
6287
  } else {
6225
6288
  log2(`Skipping audit log (apiKey: ${this.config.apiKey ? "test key" : "not set"})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solongate/proxy",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "MCP security proxy — protect any MCP server with customizable policies, path/command constraints, rate limiting, and audit logging. Zero code changes required.",
5
5
  "type": "module",
6
6
  "bin": {