Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: describe privacy opt-out auto-approve as draft preparation, never auto-send (#13093)
Adam Eivy62b64c23b63f
diff --git a/client/src/components/privacy/PrivacyBrokersTab.jsx b/client/src/components/privacy/PrivacyBrokersTab.jsxindex 1ae2164f91..d6764be261 100644--- a/client/src/components/privacy/PrivacyBrokersTab.jsx+++ b/client/src/components/privacy/PrivacyBrokersTab.jsx@@ -181,7 +181,7 @@ export default function PrivacyBrokersTab({ subjectId, consentScopes, onManageCo};const toggleAutoApprove = async () => {const next = await saveSchedule({ autoApproveOptOutEmails: !schedule.autoApproveOptOutEmails });- if (next) toast.success(next.autoApproveOptOutEmails ? 'Auto-approve opt-out emails ON' : 'Auto-approve opt-out emails OFF');+ if (next) toast.success(next.autoApproveOptOutEmails ? 'Pre-approve opt-out email drafts ON' : 'Pre-approve opt-out email drafts OFF');};const saveCron = async () => {const next = await saveSchedule({ cronExpression: cronDraft.trim() });@@ -328,8 +328,8 @@ export default function PrivacyBrokersTab({ subjectId, consentScopes, onManageCodisabled={scheduleSaving}className="accent-port-accent"/>- <span className="text-sm text-gray-200">Auto-approve opt-out emails</span>- <span className="text-[11px] text-gray-500">standing authorization — off means each draft waits for approval in Comms</span>+ <span className="text-sm text-gray-200">Pre-approve opt-out email drafts</span>+ <span className="text-[11px] text-gray-500">pre-approves the draft only; you still send it from Comms. Web forms always queue as human tasks</span></label></div>)}diff --git a/server/lib/privacyValidation.js b/server/lib/privacyValidation.jsindex e95f0536e0..406e71d838 100644--- a/server/lib/privacyValidation.js+++ b/server/lib/privacyValidation.js@@ -392,9 +392,11 @@ export const privacyScanStartSchema = z.object({// OPT-OUT AUTOMATION ENGINE SCHEMAS (issue #2145, epic #2138)// =============================================================================// Zod schemas for the opt-out run/verify actions + the user-configured recheck-// settings slice (`settings.privacy.recheck`). The engine reads its submission-// autonomy (auto-approve emails / auto-submit web forms) from that slice —-// BOTH default OFF (a fresh install never auto-sends or auto-submits anything).+// settings slice (`settings.privacy.recheck`). The engine reads+// `autoApproveOptOutEmails` from that slice (default OFF): it only pre-approves+// opt-out email drafts; nothing is ever sent or submitted unattended.+// `autoSubmitWebForms` is a legacy key kept so stored settings still validate;+// the engine ignores it (web forms are always queued for the human).// POST /api/privacy/optout — run one opt-out pass. `runVerification` (default// true) folds the verification poll into the same pass.diff --git a/server/routes/privacy.js b/server/routes/privacy.jsindex 4eb79ebd46..bfa359182e 100644--- a/server/routes/privacy.js+++ b/server/routes/privacy.js@@ -366,8 +366,9 @@ router.post('/scan', asyncHandler(async (req, res) => {// ─── Opt-out automation engine (issue #2145) ───────────────────────────────// User-triggered opt-out pass: submit found/indirect cases via the chosen lane-// (web-form / email), poll verifications. Submission autonomy (auto-send /-// auto-submit) is read from settings.privacy.recheck — both default OFF.+// (web-form / email), poll verifications. Email drafts are prepared (and+// pre-approved when settings.privacy.recheck.autoApproveOptOutEmails is on,+// default OFF) for the human to send; web forms are queued as human tasks.router.post('/optout', asyncHandler(async (req, res) => {const { runVerification, subjectId } = validateRequest(privacyOptOutPassSchema, req.body ?? {});res.json(await runOptOutPass({diff --git a/server/services/privacyOptOut.js b/server/services/privacyOptOut.jsindex 60c21ec7c9..d817ba6dd2 100644--- a/server/services/privacyOptOut.js+++ b/server/services/privacyOptOut.js@@ -5,14 +5,15 @@* Phase 5 scan/case backbone. Two submission lanes + a verification loop + a* human-task digest + a user-configured recheck schedule (privacyRecheckScheduler.js):*- * - Web-form lane → browserService (real Chrome over CDP, SSRF-pinned nav).- * Detects CAPTCHA / anti-bot walls and records `blocked` — NEVER defeats- * them. Auto-submit is OFF by default; the default surfaces the prepared- * request + playbook as a `human_task_queued` digest item.+ * - Web-form lane → queues a human task (no unattended submission).+ * PortOS never submits a web form for the operator: it surfaces the prepared+ * request + playbook as a `human_task_queued` digest item. `blocked` comes+ * from scan verdicts (anti-bot walls), which are NEVER defeated.* - Email lane → renders a CCPA/CPRA/GDPR/generic rights-request template,* recipient LOCKED to the broker record's declared address, into the- * messages drafts queue. Auto-send only behind the explicit settings toggle- * `privacy.recheck.autoApproveOptOutEmails` (default false).+ * messages drafts queue. The settings toggle+ * `privacy.recheck.autoApproveOptOutEmails` (default false) only pre-approves+ * the draft; sending stays a human step in Comms.* - Verification → scans the synced Gmail inbox for broker confirmation* mail, anti-phishing scores it (link domain must match the broker's own* domains) before advancing `submitted → verification_pending`, and a@@ -273,59 +274,36 @@ export function scoreVerificationEmail(message, broker) {// ─── Lane executors (side-effecting; injectable) ────────────────────────────/**- * WEB-FORM lane. Default-safe: prepares the request and queues it as a human- * task with the playbook + prepared disclosure, UNLESS auto-submit is enabled.- * When enabled, it SSRF-pin-navigates the opt-out URL, detects an anti-bot wall- * (→ `blocked`, never defeated) and otherwise records `submitted` with screenshot- * evidence. A form that demands more than planned mid-flow → `human_task_queued`- * (never discloses extra PII). Deps injectable so the run loop is testable.+ * WEB-FORM lane. PortOS never submits a broker web form on the operator's+ * behalf (that is external publication, a human step): the case is queued as a+ * `human_task_queued` digest item carrying the playbook and the prepared+ * disclosure, and the user runs the form themselves. Never touches a CAPTCHA.*/-export async function webFormLane(broker, kase, { disclosedFields, payload, listingUrls, autoSubmit = false, probe = null, now = new Date() }) {+export async function webFormLane(broker, kase, { disclosedFields, now = new Date() }) {const optoutUrl = broker?.optout?.url;- const evidence = {- lane: 'web_form', optout_url: optoutUrl || null,- playbook: broker?.optout?.playbook || [], disclosed: disclosedFields,- };- // Default (auto-submit off): surface as a human task — the user runs the- // playbook with the prepared identifiers. Honest, and never touches a CAPTCHA.- if (!autoSubmit || !optoutUrl) {- await transitionCase(kase.id, 'human_task_queued', {- channel: 'web_form', disclosedFields, evidence: { ...evidence, requires: 'manual_submit' },- reason: !optoutUrl ? 'no_optout_url' : 'auto_submit_disabled', now,- });- return { caseId: kase.id, lane: 'web_form', outcome: 'human_task_queued' };- }- // Auto-submit path: probe the page (injectable — real impl drives CDP).- const result = probe ? await probe(optoutUrl, { broker, disclosedFields, payload, listingUrls }).catch((e) => ({ outcome: 'error', error: e?.message })) : { outcome: 'unavailable' };- if (result.outcome === 'blocked') {- // `blocked` is only reachable from a settled SCAN verdict (found / indirect /- // not_found). A `reappeared` case can't transition straight to blocked, so it- // goes to the digest as a human task with the wall reason instead — same- // net effect (a person must act), and it never trips the state machine.- const canBlock = ['found', 'indirect_exposure', 'not_found'].includes(kase.state);- const to = canBlock ? 'blocked' : 'human_task_queued';- await transitionCase(kase.id, to, { channel: 'web_form', reason: 'antibot_wall', evidence: { ...evidence, ...result.evidence }, now });- return { caseId: kase.id, lane: 'web_form', outcome: to };- }- if (result.outcome === 'submitted') {- await transitionCase(kase.id, 'optout_in_progress', { channel: 'web_form', disclosedFields, evidence, now });- const submitted = await transitionCase(kase.id, 'submitted', { channel: 'web_form', evidence: { ...evidence, screenshot: result.screenshot || null, confirmation: result.confirmation || null }, now });- return { caseId: kase.id, lane: 'web_form', outcome: 'submitted', case: submitted };- }- // Unexpected extra challenge / unavailable → human digest, no extra disclosure.- await transitionCase(kase.id, 'human_task_queued', { channel: 'web_form', disclosedFields, evidence: { ...evidence, requires: 'manual_submit', probe: result.outcome }, reason: result.outcome === 'error' ? 'probe_error' : 'needs_human', now });+ await transitionCase(kase.id, 'human_task_queued', {+ channel: 'web_form', disclosedFields,+ evidence: {+ lane: 'web_form', optout_url: optoutUrl || null,+ playbook: broker?.optout?.playbook || [], disclosed: disclosedFields,+ requires: 'manual_submit',+ },+ reason: optoutUrl ? 'manual_submit_required' : 'no_optout_url', now,+ });return { caseId: kase.id, lane: 'web_form', outcome: 'human_task_queued' };}/*** EMAIL lane. Renders the rights-request template, LOCKS the recipient to the* broker's declared address, and creates a `draft` in the messages queue.- * Auto-approve+send only when `autoApprove` (settings toggle) is on. Transitions- * the case `optout_in_progress → submitted`. Deps injectable.+ * `autoApprove` (settings toggle) only marks the draft approved; it is NEVER+ * sent from here: the user sends it from Comms. Transitions the case+ * `optout_in_progress → submitted` (the request is prepared, not yet sent).+ * Deps injectable.*/export async function emailLane(broker, kase, {disclosedFields, payload, listingUrls = [], autoApprove = false, now = new Date(),- accountsProvider = listAccounts, draftCreator = createDraft, draftApprover = approveDraft, sender = null,+ accountsProvider = listAccounts, draftCreator = createDraft, draftApprover = approveDraft,}) {const to = broker?.optout?.email;if (typeof to !== 'string' || !to.includes('@')) {@@ -350,21 +328,13 @@ export async function emailLane(broker, kase, {await transitionCase(kase.id, 'optout_in_progress', { channel: 'email', disclosedFields, evidence: { lane: 'email', to, template: templateName, draftId: draft.id, disclosed: disclosedFields }, now });- let sent = false;- if (autoApprove) {- // Standing-authorization auto-send (settings opt-in). Approve then dispatch.- await draftApprover(draft.id);- if (sender) {- const res = await sender(draft.id).catch((e) => ({ success: false, error: e?.message }));- sent = Boolean(res?.success);- }- }+ if (autoApprove) await draftApprover(draft.id);const submitted = await transitionCase(kase.id, 'submitted', {channel: 'email',- evidence: { lane: 'email', to, template: templateName, draftId: draft.id, autoApproved: autoApprove, sent, disclosed: disclosedFields },+ evidence: { lane: 'email', to, template: templateName, draftId: draft.id, autoApproved: autoApprove, disclosed: disclosedFields },now,});- return { caseId: kase.id, lane: 'email', outcome: 'submitted', draftId: draft.id, autoApproved: autoApprove, sent, case: submitted };+ return { caseId: kase.id, lane: 'email', outcome: 'submitted', draftId: draft.id, autoApproved: autoApprove, case: submitted };}// ─── Planner (pure) ─────────────────────────────────────────────────────────@@ -491,11 +461,11 @@ export async function runVerificationPass({* `found` cluster-parents-first via the chosen lane, (2) email `indirect_exposure`,* (3) poll verifications, (4) leave `blocked`/`human_task_queued` for the digest.*- * Reads submission autonomy from settings (`privacy.recheck.autoApproveOptOutEmails`,- * `privacy.recheck.autoSubmitWebForms`, both default OFF). Deps injectable.+ * Reads `privacy.recheck.autoApproveOptOutEmails` (default OFF) from settings; it+ * pre-approves drafts for the human to send. Nothing is sent or submitted here.*/export async function runOptOutPass({- now = new Date(), settingsProvider = getSettings, deps = {}, runVerification = true, subjectId,+ now = new Date(), settingsProvider = getSettings, runVerification = true, subjectId,} = {}) {// CONSENT GATE — BEFORE any vault read, broker fetch, or draft creation. NO// CONSENT, NO ACTION: a subject without an active `broker_optout` grant is@@ -505,7 +475,6 @@ export async function runOptOutPass({const settings = await settingsProvider();const recheck = settings?.privacy?.recheck || {};const autoApprove = recheck.autoApproveOptOutEmails === true;- const autoSubmit = recheck.autoSubmitWebForms === true;const scanValues = await listScanEligibleValues({ subjectId: resolvedSubjectId });const payload = buildDisclosurePayload(scanValues);@@ -540,8 +509,8 @@ export async function runOptOutPass({continue;}const result = lane === 'email'- ? await emailLane(broker, kase, { disclosedFields, payload, listingUrls, autoApprove, now, ...(deps.email || {}) })- : await webFormLane(broker, kase, { disclosedFields, payload, listingUrls, autoSubmit, now, ...(deps.webForm || {}) });+ ? await emailLane(broker, kase, { disclosedFields, payload, listingUrls, autoApprove, now })+ : await webFormLane(broker, kase, { disclosedFields, now });if (result.outcome === 'account_required') {skipped += 1;nextActions.add(result.nextAction);@@ -551,11 +520,11 @@ export async function runOptOutPass({}const verification = runVerification- ? await runVerificationPass({ now, subjectId: resolvedSubjectId, ...(deps.verification || {}) })+ ? await runVerificationPass({ now, subjectId: resolvedSubjectId }): null;- console.log(`📋 Opt-out pass: ${submitted.length} actioned, ${skipped} skipped (autoApprove=${autoApprove}, autoSubmit=${autoSubmit})`);- return { submitted, skipped, nextActions: [...nextActions], verification, subjectId: resolvedSubjectId, autonomy: { autoApprove, autoSubmit } };+ console.log(`📋 Opt-out pass: ${submitted.length} actioned, ${skipped} skipped (autoApprove=${autoApprove})`);+ return { submitted, skipped, nextActions: [...nextActions], verification, subjectId: resolvedSubjectId, autonomy: { autoApprove } };}// ─── Human-task digest ──────────────────────────────────────────────────────diff --git a/server/services/privacyOptOut.test.js b/server/services/privacyOptOut.test.jsindex 96583a7ef9..52e24def35 100644--- a/server/services/privacyOptOut.test.js+++ b/server/services/privacyOptOut.test.js@@ -210,12 +210,15 @@ describe('emailLane', () => {const states = transitionCase.mock.calls.map((c) => c[1]);expect(states).toEqual(['optout_in_progress', 'submitted']);});- it('auto-approves + sends when the toggle is on', async () => {- const sender = vi.fn(async () => ({ success: true }));- const res = await emailLane(broker, { id: 'c1' }, { disclosedFields: ['full_name', 'email'], payload, autoApprove: true, sender });+ it('auto-approve approves the draft but never sends it', async () => {+ approveDraft.mockClear();+ const res = await emailLane(broker, { id: 'c1' }, { disclosedFields: ['full_name', 'email'], payload, autoApprove: true });expect(approveDraft).toHaveBeenCalledWith('draft-1');- expect(sender).toHaveBeenCalledWith('draft-1');- expect(res.sent).toBe(true);+ expect(res).toMatchObject({ outcome: 'submitted', autoApproved: true });+ expect(res).not.toHaveProperty('sent');+ const evidence = transitionCase.mock.calls.at(-1)[2].evidence;+ expect(evidence).toMatchObject({ autoApproved: true });+ expect(evidence).not.toHaveProperty('sent');});it.each([['an Outlook account drafts over the browser transport', [{ id: 'outlook-1', type: 'outlook', canSend: true }], 'outlook-1', 'playwright'],@@ -238,27 +241,18 @@ describe('emailLane', () => {describe('webFormLane', () => {const broker = { id: 'spokeo', name: 'Spokeo', optout: { method: 'web_form', url: 'https://www.spokeo.com/optout', playbook: ['step 1'] }, disclosureFields: ['full_name', 'email', 'listing_url'] };- it('default (auto-submit off) → human_task_queued with the playbook', async () => {- const res = await webFormLane(broker, { id: 'c1' }, { disclosedFields: ['full_name'], payload: {}, listingUrls: [], autoSubmit: false });- expect(res.outcome).toBe('human_task_queued');- expect(transitionCase).toHaveBeenCalledWith('c1', 'human_task_queued', expect.objectContaining({ channel: 'web_form' }));- });- it('auto-submit + anti-bot wall → blocked (never defeated)', async () => {- const probe = vi.fn(async () => ({ outcome: 'blocked', evidence: { wall: 'captcha' } }));- const res = await webFormLane(broker, { id: 'c1', state: 'found' }, { disclosedFields: ['full_name'], payload: {}, listingUrls: [], autoSubmit: true, probe });- expect(res.outcome).toBe('blocked');- });- it('a reappeared case that hits a wall → human_task_queued (state machine safe)', async () => {- const probe = vi.fn(async () => ({ outcome: 'blocked' }));- const res = await webFormLane(broker, { id: 'c1', state: 'reappeared' }, { disclosedFields: ['full_name'], payload: {}, listingUrls: [], autoSubmit: true, probe });+ it('always queues a human task with the playbook and never submits', async () => {+ const res = await webFormLane(broker, { id: 'c1' }, { disclosedFields: ['full_name'] });expect(res.outcome).toBe('human_task_queued');+ expect(transitionCase).toHaveBeenCalledWith('c1', 'human_task_queued', expect.objectContaining({+ channel: 'web_form', reason: 'manual_submit_required',+ evidence: expect.objectContaining({ playbook: ['step 1'], requires: 'manual_submit' }),+ }));+ expect(transitionCase.mock.calls.map((c) => c[1])).not.toContain('submitted');});- it('auto-submit success → submitted', async () => {- const probe = vi.fn(async () => ({ outcome: 'submitted', screenshot: 's.png' }));- const res = await webFormLane(broker, { id: 'c1' }, { disclosedFields: ['full_name'], payload: {}, listingUrls: [], autoSubmit: true, probe });- expect(res.outcome).toBe('submitted');- const states = transitionCase.mock.calls.map((c) => c[1]);- expect(states).toEqual(['optout_in_progress', 'submitted']);+ it('records no_optout_url when the broker has no form URL', async () => {+ await webFormLane({ id: 'x', optout: {} }, { id: 'c1' }, { disclosedFields: ['full_name'] });+ expect(transitionCase).toHaveBeenCalledWith('c1', 'human_task_queued', expect.objectContaining({ reason: 'no_optout_url' }));});});@@ -278,14 +272,14 @@ describe('runOptOutPass', () => {expect(res.submitted[0].lane).toBe('email');expect(res.submitted[0].outcome).toBe('submitted');});- it('reads autonomy toggles from settings', async () => {+ it('reads the auto-approve toggle from settings', async () => {const vault = await import('./privacyVault.js');vault.listScanEligibleValues.mockResolvedValue(SCAN_VALUES);- settings.getSettings.mockResolvedValue({ privacy: { recheck: { autoApproveOptOutEmails: true, autoSubmitWebForms: true } } });+ settings.getSettings.mockResolvedValue({ privacy: { recheck: { autoApproveOptOutEmails: true } } });listBrokers.mockResolvedValue([]);listBrokerCases.mockResolvedValue([]);const res = await runOptOutPass({ runVerification: false });- expect(res.autonomy).toEqual({ autoApprove: true, autoSubmit: true });+ expect(res.autonomy).toEqual({ autoApprove: true });});});