mirror of
https://github.com/GMGNAI/gmgn-skills.git
synced 2026-07-27 16:57:44 +00:00
feat(cli): surface a notice when output sanitization strips metadata
Give operators/agents visibility into when the CLI neutralizes suspicious token metadata in an API response. - sanitizeForOutputWithCount returns the cleaned value plus the number of altered strings; sanitizeForOutput kept as a thin wrapper - printResult prints "[gmgn-cli] Notice: neutralized N suspicious metadata value(s)" to stderr when anything was filtered (extra detail under GMGN_DEBUG); sanitized JSON still goes to stdout so piping is unaffected - document the notice in the gmgn-token SKILL untrusted-data warning Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+14
-2
@@ -1,10 +1,22 @@
|
||||
import { sanitizeForOutput } from "./sanitize.js";
|
||||
import { sanitizeForOutputWithCount } from "./sanitize.js";
|
||||
|
||||
export function printResult(data: unknown, raw?: boolean): void {
|
||||
// Neutralize any attacker-controlled metadata (token name/symbol/description/
|
||||
// social links, on-chain URIs, etc.) before it is emitted and read by an AI
|
||||
// agent. Defends against indirect prompt injection via token metadata.
|
||||
const safe = sanitizeForOutput(data);
|
||||
const { data: safe, changed } = sanitizeForOutputWithCount(data);
|
||||
if (changed > 0) {
|
||||
// Surface that filtering occurred so a human/agent knows the response
|
||||
// contained suspicious metadata. Extra detail is gated behind GMGN_DEBUG.
|
||||
console.error(
|
||||
`[gmgn-cli] Notice: neutralized ${changed} suspicious metadata value(s) in this response (possible prompt-injection attempt).`
|
||||
);
|
||||
if (process.env.GMGN_DEBUG) {
|
||||
console.error(
|
||||
`[gmgn-cli] sanitized ${changed} field(s); replaced injection framing with "[filtered]" and removed hidden characters.`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (raw) {
|
||||
console.log(JSON.stringify(safe));
|
||||
} else {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user