From 93200e0daad240240d6b0e811bfefc1a21507e1d Mon Sep 17 00:00:00 2001 From: Prasanna Ramesh <44441571+Prasanna-ramesh@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:39:18 +0530 Subject: [PATCH 1/2] feat: structured credentials payload for sendEmail Co-Authored-By: Claude Sonnet 5.5 --- .changeset/quiet-mails-send.md | 6 +++++ .../aws/e2e/account-acctions.create.test.ts | 7 +++--- .../aws/e2e/account-actions.lifecycle.test.ts | 2 +- connectors/aws/src/account-actions/create.ts | 19 +++++++-------- connectors/aws/src/account-actions/enable.ts | 16 ++++++------- .../lib/iga/capabilities/email.schema.ts | 23 +++++++++++++------ .../lib/iga/capabilities/email.ts | 2 +- packages/connector-sdk/lib/test/mock-host.ts | 9 +++++--- 8 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 .changeset/quiet-mails-send.md diff --git a/.changeset/quiet-mails-send.md b/.changeset/quiet-mails-send.md new file mode 100644 index 0000000..4296517 --- /dev/null +++ b/.changeset/quiet-mails-send.md @@ -0,0 +1,6 @@ +--- +'@open-iga/connector-sdk': minor +'@open-iga/aws': minor +--- + +sendEmail now takes a structured credentials payload (system, loginUrl, username, password, passwordChangeRequired) instead of free-form subject/body. The Host renders the wording from a fixed template and validates the same schema, so connectors can't use it for phishing. diff --git a/connectors/aws/e2e/account-acctions.create.test.ts b/connectors/aws/e2e/account-acctions.create.test.ts index 15e01cf..c01b7ed 100644 --- a/connectors/aws/e2e/account-acctions.create.test.ts +++ b/connectors/aws/e2e/account-acctions.create.test.ts @@ -42,9 +42,10 @@ describe('account-actions.create', () => { // The connector must deliver credentials via the Host email capability. expect(host.hostFunctions.sentEmails.length).toBeGreaterThan(0); const sent = host.hostFunctions.sentEmails.at(-1)!; - expect(sent.subject).toBe('Your AWS access'); - expect(sent.body).toContain('AWS Login URL:'); - expect(sent.body).toContain('Password:'); + expect(sent.reason).toBe('onboarded'); + expect(sent.loginUrl).toMatch(/^https:\/\/\d+\.signin\.aws\.amazon\.com\/console$/); + expect(sent.password.length).toBeGreaterThan(0); + expect(sent.passwordChangeRequired).toBe(true); // Prove console access was actually provisioned: the login profile exists in the // emulator with the forced-reset flag. The console password itself is write-only and diff --git a/connectors/aws/e2e/account-actions.lifecycle.test.ts b/connectors/aws/e2e/account-actions.lifecycle.test.ts index bc4499e..ee86e5a 100644 --- a/connectors/aws/e2e/account-actions.lifecycle.test.ts +++ b/connectors/aws/e2e/account-actions.lifecycle.test.ts @@ -76,7 +76,7 @@ describe('account-actions.lifecycle', () => { expect(enabled.ok).toBe(true); if (enabled.ok) expect(enabled.output.enabled).toBe(true); expect(await hasLoginProfile(userName)).toBe(true); - expect(host.hostFunctions.sentEmails.at(-1)?.subject).toBe('Your AWS access has been re-enabled'); + expect(host.hostFunctions.sentEmails.at(-1)?.reason).toBe('reenabled'); // Delete — user removed entirely. const deleted = await host.callAccountActions('iam-user', 'delete', { tenant, accountId }); diff --git a/connectors/aws/src/account-actions/create.ts b/connectors/aws/src/account-actions/create.ts index 6075265..268b8a2 100644 --- a/connectors/aws/src/account-actions/create.ts +++ b/connectors/aws/src/account-actions/create.ts @@ -77,21 +77,18 @@ export const registerAccountActionCreation = (plugin: typeof awsConnector) => { password: temporaryPassword, }); - // TODO: there is a possibility the plugin could do a phishing attack; check for alternative options // Deliver credentials via the Host email capability so the password only travels // through that side channel — never through this action's return value. The Host - // injects the recipient from the invocation input; the connector supplies content only. + // injects the recipient from the invocation input; the connector supplies data only and the Host renders the wording. const loginUrl = `https://${accountIdFromArn(created.arn)}.signin.aws.amazon.com/console`; sendEmail({ - subject: 'Your AWS access', - body: [ - `Hi ${input.firstname} ${input.lastname},`, - '', - 'Here is your AWS access. You will be asked to set a new password at first sign-in.', - `AWS Login URL: ${loginUrl}`, - `Username: ${created.userName}`, - `Password: ${temporaryPassword}`, - ].join('\n'), + template: 'credentials', + reason: 'onboarded', + system: 'AWS', + loginUrl, + username: created.userName, + password: temporaryPassword, + passwordChangeRequired: true, }); return { diff --git a/connectors/aws/src/account-actions/enable.ts b/connectors/aws/src/account-actions/enable.ts index 3c5aed9..e6e5f66 100644 --- a/connectors/aws/src/account-actions/enable.ts +++ b/connectors/aws/src/account-actions/enable.ts @@ -41,15 +41,13 @@ export const registerAccountActionEnable = (plugin: typeof awsConnector) => { const loginUrl = `https://${accountIdFromArn(input.accountId)}.signin.aws.amazon.com/console`; sendEmail({ - subject: 'Your AWS access has been re-enabled', - body: [ - 'Hi,', - '', - 'Your AWS access has been re-enabled. You will be asked to set a new password at first sign-in.', - `AWS Login URL: ${loginUrl}`, - `Username: ${userName}`, - `Password: ${temporaryPassword}`, - ].join('\n'), + template: 'credentials', + reason: 'reenabled', + system: 'AWS', + loginUrl, + username: userName, + password: temporaryPassword, + passwordChangeRequired: true, }); return { enabled: true }; diff --git a/packages/connector-sdk/lib/iga/capabilities/email.schema.ts b/packages/connector-sdk/lib/iga/capabilities/email.schema.ts index 9c50970..bd68867 100644 --- a/packages/connector-sdk/lib/iga/capabilities/email.schema.ts +++ b/packages/connector-sdk/lib/iga/capabilities/email.schema.ts @@ -1,15 +1,24 @@ import * as z from 'zod/mini'; // Email is a Host capability: the Host owns routing + transport (recipient, from-address, -// SMTP/SES connection, auth, retries, deliverability, audit). A connector supplies only the -// content, so the same capability is reused across every connector. +// SMTP/SES connection, auth, retries, deliverability, audit). // -// The recipient (`to`) is deliberately NOT part of this payload: the Host already knows the -// target identity's address from the invocation input and injects it itself. That prevents a -// connector from redirecting credentials to an arbitrary address. +// A connector supplies structured data only, never free-form text. The Host renders the +// subject and body from a fixed plain-text template, so a connector can't write its own copy +// (e.g. "verify your account") and use the trusted sender for phishing. The recipient is also +// not part of the payload: the Host injects it from the invocation input. +// +// The Host must run this same schema on receipt, the connector-side parse is not a trust boundary. export const emailPayloadSchema = z.object({ - subject: z.string().check(z.minLength(1)), - body: z.string().check(z.minLength(1)), + template: z.literal('credentials'), + reason: z.enum(['onboarded', 'reenabled']), + // Human-readable name of the target system, e.g. "AWS" + system: z.string().check(z.minLength(1), z.maxLength(64), z.regex(/^[^\r\n]*$/)), + loginUrl: z.url({ protocol: /^https$/ }).check(z.maxLength(2048)), + username: z.string().check(z.minLength(1), z.maxLength(256), z.regex(/^[^\r\n]*$/)), + password: z.string().check(z.minLength(1), z.maxLength(256), z.regex(/^[^\r\n]*$/)), + // Tell the user they must set a new password at first sign-in (not every system supports it) + passwordChangeRequired: z.boolean(), }); export type EmailPayload = z.infer; diff --git a/packages/connector-sdk/lib/iga/capabilities/email.ts b/packages/connector-sdk/lib/iga/capabilities/email.ts index 44a8429..29085da 100644 --- a/packages/connector-sdk/lib/iga/capabilities/email.ts +++ b/packages/connector-sdk/lib/iga/capabilities/email.ts @@ -5,7 +5,7 @@ import { emailPayloadSchema, type EmailPayload } from './email.schema.ts'; * Send an email through the Host's `sendEmail` capability. * * - Host owns routing + transport (recipient, from-address, SMTP/SES connection, auth, retries, deliverability, audit) - * - A connector supplies only the content, so the same capability is reused across every connector + * - A connector supplies only structured data (see email.schema.ts); the Host renders the wording from a fixed template, so the same capability is reused across every connector without it being a phishing channel * - The recipient (`to`) is deliberately NOT part of this payload: the Host already knows the target identity's address from the invocation input and injects it. That prevents a * connector from redirecting credentials to an arbitrary address. * diff --git a/packages/connector-sdk/lib/test/mock-host.ts b/packages/connector-sdk/lib/test/mock-host.ts index fc1fe89..8bfdc98 100644 --- a/packages/connector-sdk/lib/test/mock-host.ts +++ b/packages/connector-sdk/lib/test/mock-host.ts @@ -14,7 +14,7 @@ import type { handlerInputOutputSchema } from '../iga/connector/validation-schem import type { entitlementHandlerInputOutputSchema } from '../iga/connector/validation-schema/connector.entitlement-handler.schema.ts'; import type { LogLevel } from '@extism/extism'; import { createFetchProxy } from './mock-fetch.ts'; -import type { EmailPayload } from '../iga/capabilities/email.schema.ts'; +import { emailPayloadSchema, type EmailPayload } from '../iga/capabilities/email.schema.ts'; export type MockedHostResult = | { ok: true; output: z.infer<(typeof handlerInputOutputSchema)[Type]['output']> } @@ -100,8 +100,11 @@ export const createMockedHost = async ({ } }, sendEmail: (callContext, offset: bigint) => { - const payload = callContext.read(offset)?.json() as EmailPayload | undefined; - if (payload) sentEmails.push(payload); + const raw = callContext.read(offset)?.json(); + // Mirror the real Host: reject anything that isn't a valid structured payload + const parsed = emailPayloadSchema.safeParse(raw); + if (!parsed.success) return 1n; + sentEmails.push(parsed.data); return 0n; }, }, From e212759fb0a27f554332fcbd1c3853e35eabab28 Mon Sep 17 00:00:00 2001 From: Prasanna Ramesh <44441571+Prasanna-ramesh@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:08:24 +0530 Subject: [PATCH 2/2] fix: changeset --- .changeset/{quiet-mails-send.md => some-trees-dress.md} | 1 - 1 file changed, 1 deletion(-) rename .changeset/{quiet-mails-send.md => some-trees-dress.md} (90%) diff --git a/.changeset/quiet-mails-send.md b/.changeset/some-trees-dress.md similarity index 90% rename from .changeset/quiet-mails-send.md rename to .changeset/some-trees-dress.md index 4296517..006bd15 100644 --- a/.changeset/quiet-mails-send.md +++ b/.changeset/some-trees-dress.md @@ -1,5 +1,4 @@ --- -'@open-iga/connector-sdk': minor '@open-iga/aws': minor ---