Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(host): match password values with one finder

Alfredo Lopezdb03bb0e2f38
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 72e547824..f9d86951e 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.497",
+ "version": "0.1.498",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.497",
+ "version": "0.1.498",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 986221fc3..a7e1eacfc 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.497",
+ "version": "0.1.498",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/core/safety/__tests__/safety.test.ts b/mcp-host/src/core/safety/__tests__/safety.test.ts
index 40e4d29b5..c61ffff48 100644
--- a/mcp-host/src/core/safety/__tests__/safety.test.ts
+++ b/mcp-host/src/core/safety/__tests__/safety.test.ts
@@ -481,6 +481,16 @@ describe('BasicSafety', () => {
expect(result.was_modified).toBe(true)
expect(result.warnings).toEqual(['Potential secret detected in shell_exec output'])
})
+
+ it('reports no warning for a configured secret inside a password value', () => {
+ // `pwd:` runs to the space and `password =` runs on from there; the
+ // joined password match covers the configured value whole.
+ const s = new BasicSafety(() => [{ name: 'DB_TOKEN', value: 'Tok3nVal' }])
+ const result = s.sanitizeOutput('shell_exec', 'pwd:password =Tok3nVal tail')
+ expect(result.content).toBe('[REDACTED] tail')
+ expect(result.was_modified).toBe(true)
+ expect(result.warnings).toEqual(['Potential secret detected in shell_exec output'])
+ })
})
describe('a configured secret made only of JSON punctuation', () => {
@@ -553,16 +563,42 @@ describe('BasicSafety', () => {
'password=aaaaaaaapwd: SuperSecretValue123 tail'
)
expect(result.was_modified).toBe(true)
- expect(result.content).toBe('[REDACTED][REDACTED] tail')
+ expect(result.content).toBe('[REDACTED] tail')
expect(result.content).not.toContain('SuperSecretValue123')
})
- it('redacts the whole value when the part before the next label is short', () => {
- const result = safety.sanitizeOutput('shell_exec', 'password=abc=pwd=defghijk tail')
+ it('keeps a short value before a label whose value is long', () => {
+ // The value of `pwd=` runs to the space inside `passwd =`, so it is
+ // `apasswd`, 7 code units, and stays.
+ const result = safety.sanitizeOutput('shell_exec', 'pwd=apasswd = hunter2hunter2 tail')
+ expect(result.was_modified).toBe(true)
+ expect(result.content).toBe('pwd=a[REDACTED] tail')
+ })
+
+ it.each([
+ ['a lowercase label', 'password=abc=pwd=defghijk tail'],
+ ['an uppercase label', 'PASSWORD=abc=PWD=defghijk tail'],
+ ])('redacts the whole value when the part before %s is short', (_label, text) => {
+ const result = safety.sanitizeOutput('shell_exec', text)
expect(result.content).toBe('[REDACTED] tail')
expect(result.content).not.toContain('abc')
})
+ it('redacts a value of 8 code units and keeps a value of 7', () => {
+ const redacted = safety.sanitizeOutput('shell_exec', 'password=abcdefgh tail')
+ expect(redacted.was_modified).toBe(true)
+ expect(redacted.content).toBe('[REDACTED] tail')
+
+ const kept = safety.sanitizeOutput('shell_exec', 'password=abcdefg tail')
+ expect(kept.was_modified).toBe(false)
+ expect(kept.content).toBe('password=abcdefg tail')
+ })
+
+ it('ends a value at a semicolon', () => {
+ const result = safety.sanitizeOutput('shell_exec', 'password=abcdefgh;user=bob')
+ expect(result.content).toBe('[REDACTED];user=bob')
+ })
+
it.each([
['a label whose short value is the next label', 'pwd=AAAAAAAApwd=pwd= S3cretValue1'],
[
diff --git a/mcp-host/src/core/safety/safety.ts b/mcp-host/src/core/safety/safety.ts
index c9b739fd2..6c7822b66 100644
--- a/mcp-host/src/core/safety/safety.ts
+++ b/mcp-host/src/core/safety/safety.ts
@@ -296,23 +296,17 @@ export class BasicSafety implements Safety {
/<<\/SYS>>/gi,
]
- // Each entry is one rule; an array entry is one rule matched with each of
- // its patterns or finders, so its warning is reported once.
- private static readonly SECRET_PATTERNS: Array<RegExp | Array<RegExp | MatchFinder>> = [
+ // Each entry is one rule.
+ private static readonly SECRET_PATTERNS: Array<RegExp | MatchFinder> = [
/(?:sk|pk|api)[_-](?:live|test|prod)[_-][a-zA-Z0-9]{16,}/g,
/(?:ghp|gho|ghs|ghr)_[a-zA-Z0-9]{36,}/g,
/(?:xox[bprs])-[a-zA-Z0-9-]+/g,
/Bearer\s+[a-zA-Z0-9._~+\/=-]{20,}/gi,
/-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/g,
- // Password values, matched twice so the coverage is the union of both:
- // - stopping before the next password label, so a label glued to the
- // value still starts a match of its own (`password=Sup3rS3cretPwd:x1`);
- // - running to the next separator from every label, so a value that
- // holds a label (`password=abc=pwd=defghijk`) is covered whole.
- [
- /(?:password|passwd|pwd)\s*[:=]\s*(?:(?!(?:password|passwd|pwd)\s*[:=])[^\s,;]){8,}/gi,
- passwordValueMatches,
- ],
+ // Password values, from every password label to the next separator, so
+ // a value that holds a label (`password=abc=pwd=defghijk`) is covered
+ // whole.
+ passwordValueMatches,
// AWS access keys
/AKIA[0-9A-Z]{16}/g,
// Slack webhook URLs
@@ -688,14 +682,13 @@ export class BasicSafety implements Safety {
find: [text => patternMatches(text, filter.pattern)],
})
}
- for (const entry of BasicSafety.SECRET_PATTERNS) {
- const patterns = Array.isArray(entry) ? entry : [entry]
+ for (const pattern of BasicSafety.SECRET_PATTERNS) {
rules.push({
replacement: BasicSafety.SECRET_REPLACEMENT,
warning: options.secretWarning,
- find: patterns.map(pattern =>
- typeof pattern === 'function' ? pattern : (text: string) => patternMatches(text, pattern)
- ),
+ find: [
+ typeof pattern === 'function' ? pattern : (text: string) => patternMatches(text, pattern),
+ ],
})
}
for (const secret of this.configuredSecretForms()) {