feat: initial Silent Send browser extension

Chrome Manifest V3 extension that intercepts personal data and
substitutes it with user-defined replacements before sending to
Claude.ai. Hooks fetch() in the page's main world to catch API
requests, with bidirectional substitution (real→fake on send,
fake→real on display via reveal mode).

Includes popup UI with mapping management, live test/diff view,
activity log with badge count, options page with import/export,
and Shadow DOM traversal for Claude.ai compatibility.

https://claude.ai/code/session_01Dvgwe7XMoSxnWXkih8p1Cw
This commit is contained in:
Claude
2026-03-25 23:26:13 +00:00
commit 4576597e64
19 changed files with 2100 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
/**
* Silent Send - Storage Manager
*
* Wraps chrome.storage.local with typed helpers for mappings,
* activity log, and settings.
*/
const KEYS = {
MAPPINGS: 'ss_mappings',
LOG: 'ss_activity_log',
SETTINGS: 'ss_settings',
};
const DEFAULT_SETTINGS = {
enabled: true,
showHighlights: false,
revealMode: false,
maxLogEntries: 200,
categories: ['name', 'email', 'phone', 'address', 'ssn', 'dob', 'general'],
};
const Storage = {
// --- Mappings ---
async getMappings() {
const result = await chrome.storage.local.get(KEYS.MAPPINGS);
return result[KEYS.MAPPINGS] || [];
},
async saveMappings(mappings) {
await chrome.storage.local.set({ [KEYS.MAPPINGS]: mappings });
},
async addMapping(mapping) {
const mappings = await this.getMappings();
const newMapping = {
id: crypto.randomUUID(),
real: mapping.real || '',
substitute: mapping.substitute || '',
category: mapping.category || 'general',
caseSensitive: mapping.caseSensitive ?? false,
enabled: mapping.enabled ?? true,
createdAt: Date.now(),
};
mappings.push(newMapping);
await this.saveMappings(mappings);
return newMapping;
},
async updateMapping(id, updates) {
const mappings = await this.getMappings();
const idx = mappings.findIndex((m) => m.id === id);
if (idx === -1) return null;
mappings[idx] = { ...mappings[idx], ...updates };
await this.saveMappings(mappings);
return mappings[idx];
},
async deleteMapping(id) {
const mappings = await this.getMappings();
const filtered = mappings.filter((m) => m.id !== id);
await this.saveMappings(filtered);
},
// --- Activity Log ---
async getLog() {
const result = await chrome.storage.local.get(KEYS.LOG);
return result[KEYS.LOG] || [];
},
async addLogEntry(entry) {
const settings = await this.getSettings();
const log = await this.getLog();
log.unshift({
...entry,
id: crypto.randomUUID(),
timestamp: Date.now(),
});
// Trim to max entries
if (log.length > settings.maxLogEntries) {
log.length = settings.maxLogEntries;
}
await chrome.storage.local.set({ [KEYS.LOG]: log });
},
async clearLog() {
await chrome.storage.local.set({ [KEYS.LOG]: [] });
},
// --- Settings ---
async getSettings() {
const result = await chrome.storage.local.get(KEYS.SETTINGS);
return { ...DEFAULT_SETTINGS, ...(result[KEYS.SETTINGS] || {}) };
},
async saveSettings(settings) {
const current = await this.getSettings();
await chrome.storage.local.set({
[KEYS.SETTINGS]: { ...current, ...settings },
});
},
};
if (typeof globalThis !== 'undefined') {
globalThis.SilentSendStorage = Storage;
}
export default Storage;
+155
View File
@@ -0,0 +1,155 @@
/**
* Silent Send - Substitution Engine
*
* Handles bidirectional substitution of personal data.
* real → fake on outbound messages, fake → real on inbound display.
*/
const SubstitutionEngine = {
/**
* Apply all mappings to text (real → substitute).
* Returns { text, replacements[] } so we can log what happened.
*/
substitute(text, mappings) {
const replacements = [];
let result = text;
// Sort by length descending so longer matches take priority
// e.g. "John Smith" matches before "John"
const sorted = [...mappings].sort(
(a, b) => b.real.length - a.real.length
);
for (const mapping of sorted) {
if (!mapping.enabled || !mapping.real || !mapping.substitute) continue;
const escaped = this._escapeRegex(mapping.real);
const regex = new RegExp(escaped, mapping.caseSensitive ? 'g' : 'gi');
let match;
while ((match = regex.exec(result)) !== null) {
replacements.push({
original: match[0],
replaced: mapping.substitute,
index: match.index,
category: mapping.category || 'general',
timestamp: Date.now(),
});
}
result = result.replace(regex, mapping.substitute);
}
return { text: result, replacements };
},
/**
* Reverse substitution (substitute → real) for inbound display.
*/
reveal(text, mappings) {
let result = text;
const sorted = [...mappings].sort(
(a, b) => b.substitute.length - a.substitute.length
);
for (const mapping of sorted) {
if (!mapping.enabled || !mapping.real || !mapping.substitute) continue;
const escaped = this._escapeRegex(mapping.substitute);
const regex = new RegExp(escaped, mapping.caseSensitive ? 'g' : 'gi');
result = result.replace(regex, mapping.real);
}
return result;
},
/**
* Check if text contains any real values that should be substituted.
*/
scan(text, mappings) {
const found = [];
for (const mapping of mappings) {
if (!mapping.enabled || !mapping.real) continue;
const escaped = this._escapeRegex(mapping.real);
const regex = new RegExp(escaped, mapping.caseSensitive ? 'g' : 'gi');
if (regex.test(text)) {
found.push({
real: mapping.real,
substitute: mapping.substitute,
category: mapping.category || 'general',
});
}
}
return found;
},
/**
* Generate a diff-style comparison between original and substituted text.
*/
diff(original, substituted, mappings) {
const chunks = [];
let i = 0;
// Simple character-level diff by finding substituted regions
const sorted = [...mappings].sort(
(a, b) => b.real.length - a.real.length
);
// Collect all match positions in the original text
const matches = [];
for (const mapping of sorted) {
if (!mapping.enabled || !mapping.real || !mapping.substitute) continue;
const escaped = this._escapeRegex(mapping.real);
const regex = new RegExp(escaped, mapping.caseSensitive ? 'g' : 'gi');
let match;
while ((match = regex.exec(original)) !== null) {
matches.push({
start: match.index,
end: match.index + match[0].length,
original: match[0],
substitute: mapping.substitute,
});
}
}
// Sort by position
matches.sort((a, b) => a.start - b.start);
// Build chunks
for (const m of matches) {
if (m.start > i) {
chunks.push({ type: 'unchanged', text: original.slice(i, m.start) });
}
chunks.push({
type: 'substituted',
original: m.original,
replacement: m.substitute,
});
i = m.end;
}
if (i < original.length) {
chunks.push({ type: 'unchanged', text: original.slice(i) });
}
return chunks;
},
_escapeRegex(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
},
};
// Support both module and content-script contexts
if (typeof globalThis !== 'undefined') {
globalThis.SubstitutionEngine = SubstitutionEngine;
}
export default SubstitutionEngine;