Skip to content

Commit c2191d6

Browse files
committed
feat(extension): block suspicious domains and copy totp via bridge
1 parent 1885efa commit c2191d6

File tree

6 files changed

+98
-14
lines changed

6 files changed

+98
-14
lines changed

browser/chromium-extension/dist/background.js

Lines changed: 29 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/chromium-extension/dist/background.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/chromium-extension/dist/content.js

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/chromium-extension/dist/content.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/chromium-extension/src/background.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,11 @@ async function handleRequestFill(
318318
};
319319
}
320320

321-
// For suspicious/unknown domains, log a warning
322-
if (assessment.risk === 'suspicious' || assessment.risk === 'unknown') {
323-
// In future: show confirmation dialog
324-
console.warn('[Persona] Fill request for untrusted domain:', host, assessment.reasons);
321+
if (assessment.risk === 'suspicious') {
322+
return {
323+
success: false,
324+
error: `user_confirmation_required: domain flagged as suspicious (${assessment.reasons.join('; ') || host})`
325+
};
325326
}
326327

327328
const response = await requestFill(origin, itemId, userGesture);
@@ -354,6 +355,20 @@ async function handleGetTotp(
354355
userGesture = true
355356
): Promise<AutofillResult<{ code: string; remaining_seconds: number; period: number }>> {
356357
try {
358+
const policies = await getPolicies();
359+
const host = new URL(origin).hostname;
360+
const assessment = evaluateDomain(host, policies);
361+
362+
if (assessment.risk === 'blocked') {
363+
return { success: false, error: 'Domain is blocked by policy' };
364+
}
365+
if (assessment.risk === 'suspicious') {
366+
return {
367+
success: false,
368+
error: `user_confirmation_required: domain flagged as suspicious (${assessment.reasons.join('; ') || host})`
369+
};
370+
}
371+
357372
const response = await getTotp(origin, itemId, userGesture);
358373

359374
if (!response.ok) {
@@ -389,6 +404,20 @@ async function handleCopy(
389404
return { success: false, error: 'Origin is required for copy requests' };
390405
}
391406

407+
const policies = await getPolicies();
408+
const host = new URL(origin).hostname;
409+
const assessment = evaluateDomain(host, policies);
410+
411+
if (assessment.risk === 'blocked') {
412+
return { success: false, error: 'Domain is blocked by policy' };
413+
}
414+
if (assessment.risk === 'suspicious') {
415+
return {
416+
success: false,
417+
error: `user_confirmation_required: domain flagged as suspicious (${assessment.reasons.join('; ') || host})`
418+
};
419+
}
420+
392421
const response = await copyToClipboard(origin, itemId, field, userGesture);
393422

394423
if (!response.ok) {

browser/chromium-extension/src/content.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,23 @@ async function requestTotp(itemId: string, targetInput?: HTMLInputElement) {
312312
fillInput(input, code);
313313
showNotification('2FA code filled', 'success');
314314
} else {
315-
await copyToClipboard(code);
316-
showNotification('2FA code copied', 'success');
315+
const copied = await chrome.runtime
316+
.sendMessage({
317+
type: 'persona_copy',
318+
origin: location.origin,
319+
itemId,
320+
field: 'totp',
321+
userGesture: true
322+
})
323+
.then((r) => Boolean(r?.success && r?.data?.copied))
324+
.catch(() => false);
325+
326+
if (copied) {
327+
showNotification('2FA code copied', 'success');
328+
} else {
329+
await copyToClipboard(code);
330+
showNotification('2FA code copied (fallback)', 'success');
331+
}
317332
}
318333
} else {
319334
console.error('[Persona] TOTP failed:', response?.error);

0 commit comments

Comments
 (0)