Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/some-trees-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@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.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
7 changes: 4 additions & 3 deletions connectors/aws/e2e/account-acctions.create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/e2e/account-actions.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
19 changes: 8 additions & 11 deletions connectors/aws/src/account-actions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 7 additions & 9 deletions connectors/aws/src/account-actions/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
23 changes: 16 additions & 7 deletions packages/connector-sdk/lib/iga/capabilities/email.schema.ts
Original file line number Diff line number Diff line change
@@ -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<typeof emailPayloadSchema>;
2 changes: 1 addition & 1 deletion packages/connector-sdk/lib/iga/capabilities/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 6 additions & 3 deletions packages/connector-sdk/lib/test/mock-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type extends ConnectorAccountAction['type']> =
| { ok: true; output: z.infer<(typeof handlerInputOutputSchema)[Type]['output']> }
Expand Down Expand Up @@ -100,8 +100,11 @@ export const createMockedHost = async <const Config extends ConnectorConfig>({
}
},
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;
},
},
Expand Down
Loading