MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / sanitizeInput

Function sanitizeInput

server/src/addie/security.ts:62–99  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

60 * Sanitize user input before passing to Claude
61 */
62export function sanitizeInput(text: string): SanitizationResult {
63 let sanitized = text;
64 let flagged = false;
65 let reason: string | undefined;
66
67 // Check for suspicious patterns
68 for (const pattern of SUSPICIOUS_PATTERNS) {
69 if (pattern.test(text)) {
70 flagged = true;
71 reason = `Suspicious pattern detected`;
72 logger.warn({ pattern: pattern.source.substring(0, 50) }, 'Addie: Suspicious input pattern');
73 break;
74 }
75 }
76
77 // Remove potential delimiter injection
78 sanitized = sanitized
79 .replace(/\[system\]/gi, '[sys tem]')
80 .replace(/\[user\]/gi, '[us er]')
81 .replace(/\[assistant\]/gi, '[assis tant]');
82
83 // Limit message length to prevent context stuffing
84 const MAX_LENGTH = 4000;
85 if (sanitized.length > MAX_LENGTH) {
86 sanitized = sanitized.substring(0, MAX_LENGTH) + '... [truncated]';
87 if (!flagged) {
88 flagged = true;
89 reason = 'Message truncated due to excessive length';
90 }
91 }
92
93 return {
94 valid: true,
95 sanitized,
96 flagged,
97 reason,
98 };
99}
100
101/**
102 * Convert markdown links to Slack mrkdwn format.

Callers 13

createSiChatRoutesFunction · 0.85
createAddieAdminRouterFunction · 0.85
createTavusRouterFunction · 0.85
createAddieChatRouterFunction · 0.85
handleUserMessageFunction · 0.85
handleAppMentionFunction · 0.85
handleDirectMessageFunction · 0.85
handleActiveThreadReplyFunction · 0.85
handleChannelMessageFunction · 0.85
handleEmailConversationFunction · 0.85
handleAssistantMessageFunction · 0.85
handleAppMentionFunction · 0.85

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected