Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(security): export sanitizer never stripped simpleMemory conversations
trohitg8310818ef16d
diff --git a/.opencompany/workflows/AI Assistant_example_workflow-1779017037684-e2e5da7a.json b/.opencompany/workflows/AI Assistant_example_workflow-1779017037684-e2e5da7a.jsonindex bbcc2165..471bc16e 100644--- a/.opencompany/workflows/AI Assistant_example_workflow-1779017037684-e2e5da7a.json+++ b/.opencompany/workflows/AI Assistant_example_workflow-1779017037684-e2e5da7a.json@@ -535,7 +535,7 @@"simpleMemory-17842180572672-160ec5": {"session_id": "","window_size": 100,- "memory_content": "# Conversation History\n\n\n### **Human** (2026-07-16 22:28:22)\ncheck my website stats. \n\n### **Assistant** (2026-07-16 22:28:22)\nI checked your Cloudflare account to see if we could retrieve Web Analytics or Zone Analytics directly. Here is what I found:\n\n1. **Your Registered Domains (Zones):**\n * **`opencompany.sh`** (Zone ID: `9c737b1defb232d13e064ea9999b3bba`) — *Active*\n * **`zeenie.work`** (Zone ID: `c0e6d30b2af34e7fa46e03c423919fb2`) — *Active*\n * **`zeenie.xyz`** (Zone ID: `383a52b2b8054a6725a5cd0528e9a6b8`) — *Active*\n\n2. **API Access & Limitations:**\n * Cloudflare's legacy **Zone Analytics API** has been sunsetted and replaced by their GraphQL API.\n * Attempting to query the newer Web Analytics (RUM / Site Info) endpoints returned an `Authentication error (403 Forbidden)`, indicating that your current API token permissions do not have the required scopes to read Web Analytics/RUM data.\n\n### How to proceed:\nTo check your website stats, you can:\n1. **Update your API Token:** If you want me to pull these stats programmatically, please update your Cloudflare API token to include **Analytics (Read)** or **Web Analytics (Read)** permissions.\n2. **Specify a site:** Let me know which of the three websites (`opencompany.sh`, `zeenie.work`, or `zeenie.xyz`) you are focusing on, and I can check other configuration/DNS details if needed!\n",+ "memory_content": "# Conversation History\n\n*No messages yet.*\n","long_term_enabled": false,"retrieval_count": 3,"last_session_id": null,diff --git a/.opencompany/workflows/Claude Assistant_example_workflow-1779095939967-2369cff4.json b/.opencompany/workflows/Claude Assistant_example_workflow-1779095939967-2369cff4.jsonindex 53d92d31..fbccc875 100644--- a/.opencompany/workflows/Claude Assistant_example_workflow-1779095939967-2369cff4.json+++ b/.opencompany/workflows/Claude Assistant_example_workflow-1779095939967-2369cff4.json@@ -505,7 +505,7 @@"memory_content": "# Conversation History\n\n*No messages yet.*\n","long_term_enabled": false,"retrieval_count": 3,- "last_session_id": "45dbf1ac-1221-495d-9207-61b3559713ee",+ "last_session_id": null,"sessionId": "","windowSize": 100,"longTermEnabled": false,diff --git a/client/src/utils/__tests__/parameterSanitizer.test.ts b/client/src/utils/__tests__/parameterSanitizer.test.tsnew file mode 100644index 00000000..19463d7f--- /dev/null+++ b/client/src/utils/__tests__/parameterSanitizer.test.ts@@ -0,0 +1,165 @@+import { describe, it, expect } from 'vitest';+import { sanitizeParameters } from '../parameterSanitizer';++/**+ * The regression these tests exist for: the runtime denylist held the+ * camelCase `memoryContent` while the backend field is `memory_content`, so the+ * exact-match check never fired and every export carried the Simple Memory+ * node's full conversation history.+ *+ * Names asserted here are the *backend* field names. If one is renamed in the+ * Pydantic model, this file should fail.+ */+describe('sanitizeParameters', () => {+ describe('simpleMemory runtime state', () => {+ it('strips the conversation history', () => {+ const out = sanitizeParameters({+ memory_content: '# Conversation History\n\n### **Human**\nmy api token is hunter2',+ window_size: 100,+ });+ expect(out).not.toHaveProperty('memory_content');+ expect(out.window_size).toBe(100);+ });++ it('strips the last Claude session id', () => {+ const out = sanitizeParameters({+ last_session_id: '45dbf1ac-1221-495d-9207-61b3559713ee',+ });+ expect(out).not.toHaveProperty('last_session_id');+ });++ it('keeps genuine configuration on the same node', () => {+ const out = sanitizeParameters({+ memory_content: 'secrets in here',+ session_id: '',+ window_size: 50,+ long_term_enabled: true,+ retrieval_count: 3,+ embedding_provider: 'huggingface',+ embedding_endpoint: 'http://localhost:11434',+ });+ expect(out).toEqual({+ session_id: '',+ window_size: 50,+ long_term_enabled: true,+ retrieval_count: 3,+ embedding_provider: 'huggingface',+ embedding_endpoint: 'http://localhost:11434',+ });+ });+ });++ describe('spelling can no longer disable a filter', () => {+ it.each([+ 'memory_content',+ 'memoryContent',+ 'MemoryContent',+ 'MEMORY_CONTENT',+ 'memory-content',+ ])('strips %s', key => {+ expect(sanitizeParameters({ [key]: 'history' })).toEqual({});+ });++ it.each(['api_key', 'apiKey', 'apikey', 'API_KEY'])('strips %s', key => {+ expect(sanitizeParameters({ [key]: 'sk-live-1234' })).toEqual({});+ });++ it.each(['access_token', 'accessToken', 'refresh_token', 'refreshToken'])(+ 'strips %s',+ key => {+ expect(sanitizeParameters({ [key]: 'ya29.abc' })).toEqual({});+ },+ );+ });++ describe('credentials', () => {+ it('strips exact and substring credential keys', () => {+ const out = sanitizeParameters({+ password: 'p',+ client_secret: 's',+ private_key: 'k',+ cloudflare_api_token: 't',+ some_auth_token: 't',+ keep_me: 'ok',+ });+ expect(out).toEqual({ keep_me: 'ok' });+ });++ it('keeps cloud_tool_key, which is an identifier and not a credential', () => {+ // vertexCloudTool's only identifying config. A plausible-looking+ // `endsWith("key")` rule would destroy this node on export.+ const out = sanitizeParameters({+ cloud_tool_key: 'type:web_search',+ label: 'Web Search',+ });+ expect(out).toEqual({ cloud_tool_key: 'type:web_search', label: 'Web Search' });+ });++ it('keeps other real param names that merely look credential-ish', () => {+ const out = sanitizeParameters({+ keyword: 'pizza',+ keywords: ['a', 'b'],+ authentication: 'none',+ allow_unauthenticated: true,+ allowed_credentials: ['openai'],+ include_author: true,+ });+ expect(Object.keys(out).sort()).toEqual([+ 'allow_unauthenticated',+ 'allowed_credentials',+ 'authentication',+ 'include_author',+ 'keyword',+ 'keywords',+ ]);+ });++ it('does not fire on token-shaped but harmless names', () => {+ const out = sanitizeParameters({+ max_tokens: 4096,+ maxTokens: 4096,+ budget_tokens: 1024,+ page_token: 'abc',+ nextPageToken: 'def',+ total_tokens: 10,+ input_tokens: 4,+ output_tokens: 6,+ });+ expect(Object.keys(out).sort()).toEqual(+ [+ 'budget_tokens',+ 'input_tokens',+ 'maxTokens',+ 'max_tokens',+ 'nextPageToken',+ 'output_tokens',+ 'page_token',+ 'total_tokens',+ ].sort(),+ );+ });+ });++ describe('traversal', () => {+ it('recurses into nested objects', () => {+ const out = sanitizeParameters({+ outer: { api_key: 'sk-1', keep: 1, deeper: { memory_content: 'x', ok: 2 } },+ });+ expect(out).toEqual({ outer: { keep: 1, deeper: { ok: 2 } } });+ });++ it('drops a nested object that becomes empty', () => {+ expect(sanitizeParameters({ creds: { api_key: 'sk-1' } })).toEqual({});+ });++ it('passes arrays through unchanged', () => {+ const out = sanitizeParameters({ tasks: [{ api_key: 'sk-1' }] });+ expect(out.tasks).toEqual([{ api_key: 'sk-1' }]);+ });++ it('preserves falsy values that are real configuration', () => {+ const out = sanitizeParameters({ enabled: false, count: 0, note: '' });+ expect(out).toEqual({ enabled: false, count: 0, note: '' });+ });+ });+});diff --git a/client/src/utils/parameterSanitizer.ts b/client/src/utils/parameterSanitizer.tsindex 6b6b7577..ea95c3f0 100644--- a/client/src/utils/parameterSanitizer.ts+++ b/client/src/utils/parameterSanitizer.ts@@ -1,70 +1,127 @@/*** Parameter Sanitizer- * Strips sensitive credentials from node parameters before export.- * Prevents API keys, tokens, and passwords from leaking into exported workflow JSON.+ * Strips sensitive credentials and runtime state from node parameters before export.+ * Prevents API keys, tokens, passwords and conversation history from leaking into+ * exported workflow JSON.+ *+ * ## Every comparison here is normalization-insensitive, deliberately+ *+ * Parameter keys are defined by backend Pydantic models and cross the wire as+ * `snake_case` (see the naming table in CLAUDE.md). This file is TypeScript, so+ * it is very easy to write the `camelCase` spelling and produce a filter that+ * silently matches nothing.+ *+ * That is not hypothetical: `memoryContent` sat in the runtime list below while+ * the real field was `memory_content`, so `Set.has()` never matched and every+ * export carried the Simple Memory node's full conversation history. It reached+ * the shipped example workflows, and from there a public repository.+ *+ * So keys are compared after `normalizeKey`, which folds case and drops+ * separators. `memoryContent`, `memory_content` and `MEMORY-CONTENT` are all one+ * key. Listing a name in either spelling now works, and getting the spelling+ * wrong can no longer disable a filter.*/-// Parameter names that should never appear in exported JSON-const SENSITIVE_EXACT_KEYS = new Set([- 'apiKey', 'api_key', 'apikey',- 'accessToken', 'access_token',- 'refreshToken', 'refresh_token',+/** Fold case and drop separators so snake_case and camelCase collapse together. */+function normalizeKey(key: string): string {+ return key.toLowerCase().replace(/[_\-\s]/g, '');+}++const normalizedSet = (keys: string[]): Set<string> =>+ new Set(keys.map(normalizeKey));++// Parameter names that should never appear in exported JSON.+const SENSITIVE_EXACT_KEYS = normalizedSet([+ 'api_key',+ 'access_token',+ 'refresh_token','secret', 'password', 'passwd',- 'client_id', 'client_secret', 'clientId', 'clientSecret',- 'token', 'bearerToken', 'bearer_token',- 'privateKey', 'private_key',- 'encryptionKey', 'encryption_key',- 'oauthToken', 'oauth_token',+ 'client_id', 'client_secret',+ 'token', 'bearer_token',+ 'private_key',+ 'encryption_key',+ 'oauth_token',]);-// Legitimate parameter names that contain sensitive substrings but are NOT credentials.-// These are checked first and always allowed through.-const SAFE_KEYS = new Set([- 'maxTokens', 'max_tokens',- 'budgetTokens', 'budget_tokens',- 'page_token', 'pageToken', 'nextPageToken', 'next_page_token',- 'tokenCount', 'token_count',- 'totalTokens', 'total_tokens',- 'inputTokens', 'input_tokens',- 'outputTokens', 'output_tokens',+// Legitimate parameter names that contain sensitive substrings but are NOT+// credentials. Checked first and always allowed through.+const SAFE_KEYS = normalizedSet([+ 'max_tokens',+ 'budget_tokens',+ 'page_token', 'next_page_token',+ 'token_count',+ 'total_tokens',+ 'input_tokens',+ 'output_tokens',]);-// Substring patterns - if a key contains any of these (case-insensitive),-// the value is stripped. Uses specific credential patterns to avoid-// false positives on parameter names like "maxTokens" or "page_token".+// Substring patterns - if a key contains any of these once normalized, the+// value is stripped. Specific enough to avoid firing on `maxTokens`/`pageToken`,+// which are additionally protected by SAFE_KEYS above.const SENSITIVE_SUBSTRINGS = [- 'api_key', 'apikey',+ 'api_key','secret','password',- 'private_key', 'privatekey',- 'accesstoken', 'access_token',- 'refreshtoken', 'refresh_token',- 'bearertoken', 'bearer_token',- 'oauthtoken', 'oauth_token',- 'authtoken', 'auth_token',-];+ 'private_key',+ 'access_token',+ 'refresh_token',+ 'bearer_token',+ 'oauth_token',+ 'auth_token',+].map(normalizeKey);++// Suffix rules, to catch vendor-prefixed credentials nobody has added yet+// (`bot_token`, `vercel_token`, ...) without enumerating every vendor.+//+// `token` singular only. Plural `tokens` is always a *count* in this codebase+// (`max_tokens`, `total_tokens`, `input_tokens`), so the singular suffix+// separates the two with no overlap.+//+// There is deliberately no `key` suffix rule. It reads plausible and it is+// wrong: `vertexCloudTool.cloud_tool_key` is the stable identifier of a+// cloud-side tool (`type:...` / `fn:...`), so stripping it would silently+// destroy that node on export. Credential-shaped `*_key` names are already+// covered by the `api_key` / `private_key` substrings above. Verified against+// every Params field on all registered plugins -- do not add `key` here+// without re-running that check.+const SENSITIVE_SUFFIXES = ['token'];/*** Check if a parameter key holds sensitive credential data.* Returns true if the key should be stripped from exports.*/function isSensitiveKey(key: string): boolean {- if (SAFE_KEYS.has(key)) return false;- if (SENSITIVE_EXACT_KEYS.has(key)) return true;- const lower = key.toLowerCase();- return SENSITIVE_SUBSTRINGS.some(sub => lower.includes(sub));+ const normalized = normalizeKey(key);+ if (SAFE_KEYS.has(normalized)) return false;+ if (SENSITIVE_EXACT_KEYS.has(normalized)) return true;+ if (SENSITIVE_SUBSTRINGS.some(sub => normalized.includes(sub))) return true;+ return SENSITIVE_SUFFIXES.some(suffix => normalized.endsWith(suffix));}-// Runtime/state keys that should not appear in exported workflows.-// These are transient execution state, not user configuration.-const RUNTIME_KEYS = new Set([- 'memoryContent', // Conversation history (personal data)+// Runtime/state keys that should not appear in exported workflows. These are+// transient execution state that happens to be persisted as a parameter, not+// user configuration, and several of them carry personal data.+//+// Names below are the backend field names. Do NOT add a key here on the basis+// of a `hidden: true` UI flag -- that marks merely-advanced configuration+// (`model`, `max_parallel`, `effort`), which an export legitimately needs.+const RUNTIME_KEYS = normalizedSet([+ // simpleMemory: the whole conversation, verbatim, including anything the+ // user or the model said.+ 'memory_content',+ // simpleMemory: the Claude Code session UUID from the last successful run.+ 'last_session_id','token_usage', // Execution token metrics'execution_time', // Runtime timing'last_execution', // Last execution result'last_result', // Cached result]);+/** True if the key is runtime state rather than user configuration. */+function isRuntimeKey(key: string): boolean {+ return RUNTIME_KEYS.has(normalizeKey(key));+}+/*** Deep-strip sensitive and runtime keys from a parameter object.* Returns a new object with sensitive values removed.@@ -78,7 +135,7 @@ export function sanitizeParameters(params: Record<string, any>): Record<string,if (isSensitiveKey(key)) continue;// Skip runtime/state keys- if (RUNTIME_KEYS.has(key)) continue;+ if (isRuntimeKey(key)) continue;// Recurse into nested objects (but not arrays or null)if (value && typeof value === 'object' && !Array.isArray(value)) {