You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 361895a
Browse filesBrowse the repository at this point in the historyBrowse files
MCP: encode the tools' input schemas instead of splicing them into JSON text
The lab_scan and scan input schemas were built with fmt.Sprintf, placing
marshalled values and plain strings into a hand-written JSON document
(CodeQL go/unsafe-quoting, alerts 12-17). The marshalled enums were safe,
but the allow-list was joined straight into a quoted description, so a
value holding a quote would have produced a broken or altered schema.
The schemas are now Go values encoded by encoding/json. schemaObject keeps
the properties in the order written; the only bytes written by hand are
braces, colons and commas. The served schemas are equivalent, in compact
form. A test feeds a value with a quote, backslash and newline through the
scan tool's schema and checks it stays inside its string.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
// remediationProps are the scan settings an agent can change after a verdict
309
362
// that is not complete (#269). None can raise the operator's caps.
310
-
varremediationProps=fmt.Sprintf(`,
311
-
"retry_inconclusive": {"type": "boolean", "description": "At the end, look up once more every name that timed out, was refused or failed; an answer replaces the first outcome. Use it when failures degraded the verdict."},
312
-
"auto_rate": {"type": "boolean", "description": "Halve the query rate while many lookups fail and raise it again once they succeed, never above the starting rate, instead of giving up."},
313
-
"exclude": {"type": "array", "items": {"type": "string"}, "maxItems": %d, "description": "Names out of scope that are never queried: one name (mail.example.com) or a branch (*.corp.example.com)."},
314
-
"depth": {"type": "integer", "minimum": 1, "maximum": %d, "description": "Enumerate the words again under every name found, down to this many levels; default 1, no recursion. Every level stays within max_queries."}`,
315
-
maxMCPExclude, maxMCPDepth)
363
+
varremediationProps=schemaObject{
364
+
{"retry_inconclusive", map[string]any{"type": "boolean", "description": "At the end, look up once more every name that timed out, was refused or failed; an answer replaces the first outcome. Use it when failures degraded the verdict."}},
365
+
{"auto_rate", map[string]any{"type": "boolean", "description": "Halve the query rate while many lookups fail and raise it again once they succeed, never above the starting rate, instead of giving up."}},
366
+
{"exclude", map[string]any{"type": "array", "items": map[string]any{"type": "string"}, "maxItems": maxMCPExclude, "description": "Names out of scope that are never queried: one name (mail.example.com) or a branch (*.corp.example.com)."}},
367
+
{"depth", map[string]any{"type": "integer", "minimum": 1, "maximum": maxMCPDepth, "description": "Enumerate the words again under every name found, down to this many levels; default 1, no recursion. Every level stays within max_queries."}},
368
+
}
316
369
317
370
// remediation holds the remediationProps arguments.
// recordTypeSchema offers every type -type accepts (#264).
341
-
varrecordTypeSchema=func() json.RawMessage {
342
-
enum, _:=json.Marshal(dns.Types())
343
-
returnjson.RawMessage(`{"type": "array", "items": {"enum": `+string(enum) +`}, "description": "Record types to look up; default A and AAAA. CNAME and NS add takeover hints."}`)
344
-
}()
394
+
varrecordTypeSchema=map[string]any{
395
+
"type": "array",
396
+
"items": map[string]any{"enum": dns.Types()},
397
+
"description": "Record types to look up; default A and AAAA. CNAME and NS add takeover hints.",
398
+
}
345
399
346
400
funclabScanTool(cfgmcpConfig) mcp.Tool {
347
-
scenarios, _:=json.Marshal(labScenarios())
348
-
scenarioDesc, _:=json.Marshal(fmt.Sprintf("Lab scenario to scan; default lab1-first-scan. Each is a fictional zone for %s served on this machine.%s",
349
-
labDomain, labScenarioGuide()))
350
-
schema:=fmt.Sprintf(`{
351
-
"type": "object",
352
-
"properties": {
353
-
"scenario": {"enum": %s, "description": %s},
354
-
"words": {"type": "array", "items": {"type": "string"}, "maxItems": %d, "description": "Subdomain labels to try; default the labs' short wordlist."},
355
-
"types": %s,
356
-
"rate": {"type": "integer", "minimum": 0, "maximum": 1000, "description": "Queries per second; 0 or absent is unlimited. Lab traffic stays on this machine."},
{"scenario", map[string]any{"enum": labScenarios(), "description": fmt.Sprintf("Lab scenario to scan; default lab1-first-scan. Each is a fictional zone for %s served on this machine.%s",
403
+
labDomain, labScenarioGuide())}},
404
+
{"words", wordsSchema("Subdomain labels to try; default the labs' short wordlist.")},
405
+
{"types", recordTypeSchema},
406
+
{"rate", map[string]any{"type": "integer", "minimum": 0, "maximum": 1000, "description": "Queries per second; 0 or absent is unlimited. Lab traffic stays on this machine."}},
{"force", map[string]any{"type": "boolean", "description": "Scan a wildcard zone anyway, filtering answers that match the wildcard."}},
409
+
}, remediationProps...))
362
410
return mcp.Tool{
363
411
Name: "lab_scan",
364
412
Title: "Scan a lab zone",
365
413
Description: fmt.Sprintf("Enumerate subdomains of %s in one of subenum's lab scenarios: fictional zones answered by a DNS server on this machine, so no traffic leaves it. Safe for practice and for learning how wildcards, rate limits and failing resolvers change a scan's verdict.", labDomain),
366
-
InputSchema: json.RawMessage(schema),
414
+
InputSchema: schema,
367
415
OutputSchema: mcpReportSchema,
368
416
Annotations: mcp.Annotations{ReadOnlyHint: true},
369
417
Call: func(ctx context.Context, raw json.RawMessage) mcp.Result {
{"domain", map[string]any{"type": "string", "description": fmt.Sprintf("Domain to enumerate: one of %s, or a subdomain of one.", strings.Join(cfg.allow, ", "))}},
479
+
{"words", wordsSchema("Subdomain labels to try; default subenum's bundled list of the most common ones.")},
480
+
{"types", recordTypeSchema},
481
+
{"max_queries", map[string]any{"type": "integer", "minimum": 1, "maximum": cfg.maxQueries, "description": fmt.Sprintf("Most names to test; default and ceiling %d.", cfg.maxQueries)}},
482
+
}
430
483
iflen(cfg.sources) >0 {
431
-
enum, _:=json.Marshal(cfg.sources)
432
-
sourcesProp=fmt.Sprintf(`,
433
-
"sources": {"type": "array", "items": {"enum": %s}, "description": "Passive sources to seed candidates from before the scan; default none. Their names are added to words after dedupe, count against max_queries, and are each verified by a lookup. One HTTPS request per source."}`, enum)
484
+
props=append(props, schemaField{"sources", map[string]any{"type": "array", "items": map[string]any{"enum": cfg.sources}, "description": "Passive sources to seed candidates from before the scan; default none. Their names are added to words after dedupe, count against max_queries, and are each verified by a lookup. One HTTPS request per source."}})
434
485
}
435
-
schema:=fmt.Sprintf(`{
436
-
"type": "object",
437
-
"properties": {
438
-
"domain": {"type": "string", "description": "Domain to enumerate: one of %s, or a subdomain of one."},
439
-
"words": {"type": "array", "items": {"type": "string"}, "maxItems": %d, "description": "Subdomain labels to try; default subenum's bundled list of the most common ones."},
440
-
"types": %s,
441
-
"max_queries": {"type": "integer", "minimum": 1, "maximum": %d, "description": "Most names to test; default and ceiling %d."}%s%s
varcalls atomic.Int64// scan calls this session has made
447
488
return mcp.Tool{
448
489
Name: "scan",
449
490
Title: "Enumerate subdomains",
450
491
Description: fmt.Sprintf("Enumerate subdomains of a real domain by DNS, through the operator's resolver at %d queries per second, testing at most %d names in %s. Only domains the operator allowed can be scanned: %s.",
0 commit comments