Mail relay: development hosts are known by pattern, with no env - built in: *.dev.netscale.pl

The launch rule called a site non-public only when IAPL_NOINDEX was set (or the project named its hosts).
The owner's development sites set nothing, so production's database copied onto a development address
counted as a launch and would have mailed real people.

- iapl({ developmentHosts }): host patterns of development addresses. Default DEFAULT_DEVELOPMENT_HOSTS =
  ['*.dev.netscale.pl'], Intecion's own development domain; a project replaces the list or empties it.
  mail.relay.developmentHosts overrides it for the mail service.
- a site whose host matches is non-public exactly as with IAPL_NOINDEX=1; either signal is enough
- siteNonPublicSignal, matchDevelopmentHost, isDevelopmentHost, pluginDevelopmentHosts exported
- panel state: nonPublicBy, nonPublicPattern; doctor: mail-non-public (info) names the signal
- every case of the launch table runs with no env on the built-in pattern
- docs, AGENT.md, skills, changelog draft

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 10:26:12 +01:00
co-authored by Claude Fable 5.2
parent 634908eb57
commit 14abf369da
26 changed files with 319 additions and 80 deletions
+21 -3
View File
@@ -661,7 +661,7 @@ describe('iapl-doctor: first-seen dates', () => {
})
describe('e-mail: transport, the mail service, Graph, the confirm route', () => {
const ids = ['mail-transport', 'mail-relay-state', 'mail-reply-address', 'mail-graph-deprecated', 'mail-relay-route']
const ids = ['mail-transport', 'mail-non-public', 'mail-relay-state', 'mail-reply-address', 'mail-graph-deprecated', 'mail-relay-route']
const relay = (extra: object = {}) => ({ connected: true, disconnected: false, nameReplaced: false, state: 'active', ...extra })
const mail = (extra: object = {}) => ({ graphEnv: false, relay: relay(), replyAddress: true, status: null, transport: 'relay', ...extra })
const run = async (deep: null | object, files: Record<string, string> = {}) =>
@@ -692,14 +692,32 @@ describe('e-mail: transport, the mail service, Graph, the confirm route', () =>
expect(copy.findings[0].message).toContain('client.pl')
expect(copy.findings[0].fix).toContain('Connect again')
// the same for a copy that has a token of its own (production's data copied back onto the development address)
expect(await run(mail({ nonPublic: true, relay: relay({ reason: 'client.pl', refusal: 'client-other-host' }) }))).toEqual(['mail-relay-state:warning'])
expect(await run(mail({ nonPublic: true, nonPublicBy: 'noindex', relay: relay({ reason: 'client.pl', refusal: 'client-other-host' }) }))).toEqual(['mail-relay-state:warning', 'mail-non-public:info'])
// a PUBLIC site whose database knows another host: the site after its launch — or a copy that forgot IAPL_NOINDEX
const launched = await doctor(project({ ...base(), 'src/payload.config.ts': 'iapl({ forms: {} })' }), ids, { deepStatus: { mail: mail({ otherHostEntries: true }) } })
expect(rules(launched)).toEqual(['mail-relay-state:info'])
expect(launched.findings[0].message).toContain('copy')
expect(launched.findings[0].fix).toContain('IAPL_NOINDEX=1')
expect(launched.findings[0].fix).toContain('otherHosts')
expect(await run(mail({ nonPublic: true, otherHostEntries: true }))).toEqual([])
expect(await run(mail({ nonPublic: true, nonPublicBy: 'noindex', otherHostEntries: true }))).toEqual(['mail-non-public:info'])
})
test('mail-non-public: says which signal makes the site a non-public copy — the development pattern, or IAPL_NOINDEX', async () => {
const find = async (deep: object) => (await doctor(project({ ...base(), 'src/payload.config.ts': 'iapl({ forms: {} })' }), ids, { deepStatus: { mail: mail(deep) } })).findings
const byHost = await find({ nonPublic: true, nonPublicBy: 'development-host', nonPublicPattern: '*.dev.netscale.pl' })
expect(byHost.map((f) => `${f.rule}:${f.severity}`)).toEqual(['mail-non-public:info'])
expect(byHost[0].message).toContain('its host matches the development pattern "*.dev.netscale.pl"')
expect(byHost[0].fix).toContain('developmentHosts')
const byEnv = await find({ nonPublic: true, nonPublicBy: 'noindex' })
expect(byEnv[0].message).toContain('IAPL_NOINDEX is set')
expect(byEnv[0].fix).toContain('remove IAPL_NOINDEX')
// the copy warning names the same signal
const held = await find({ nonPublic: true, nonPublicBy: 'development-host', nonPublicPattern: '*.dev.netscale.pl', relay: relay({ reason: 'client.pl', refusal: 'client-other-host' }) })
expect(held.map((f) => `${f.rule}:${f.severity}`)).toEqual(['mail-relay-state:warning', 'mail-non-public:info'])
expect(held[0].message).toContain('"*.dev.netscale.pl"')
// a public site, a site on SMTP: nothing
expect(await run(mail({}))).toEqual([])
expect(await run(mail({ nonPublic: true, nonPublicBy: 'noindex', relay: relay({ connected: false, state: undefined }), replyAddress: false, transport: 'smtp' }))).toEqual([])
expect(await run(mail({ relay: relay({ nameReplaced: true }) }))).toEqual(['mail-relay-state:warning'])
})
+69 -8
View File
@@ -18,13 +18,14 @@ import { RELAY_DEFAULTS, RELAY_SHORT_NAME } from '../src/modules/email/relay/co
import { createFakeRelay } from '../src/modules/email/relay/fake.js'
import { dropExpectedMail, expectMailTo, takeExpectedMail, withMailKind } from '../src/modules/email/relay/kinds.js'
import { bareAddresses, buildRelayMessage, cleanSubject } from '../src/modules/email/relay/message.js'
import { isPublicHost, relayHost, resolveRelayOptions } from '../src/modules/email/relay/options.js'
import { isPublicHost, pluginDevelopmentHosts, relayHost, resolveRelayOptions } from '../src/modules/email/relay/options.js'
import { mailPanelState } from '../src/modules/email/relay/panel.js'
import { clearUnconfirmedRelayMessages, sendThroughRelay } from '../src/modules/email/relay/send.js'
import { disconnectRelay, enrolRelay, forgetOtherHosts, getRelayStatus, provesToken, refreshRelayStatus, rotateRelayToken, setRelayToken, siteIsNonPublic } from '../src/modules/email/relay/session.js'
import { disconnectRelay, enrolRelay, forgetOtherHosts, getRelayStatus, provesToken, refreshRelayStatus, rotateRelayToken, setRelayToken, siteIsNonPublic, siteNonPublicSignal } from '../src/modules/email/relay/session.js'
import { holdNonce, otherRelayHosts, readRelayCandidate, readRelayStore, updateRelayStore } from '../src/modules/email/relay/store.js'
import { NOTIFICATION_FALLBACK, NOTIFICATION_FALLBACK_PL } from '../src/modules/notifications/defaults.js'
import { resolveFormMessage } from '../src/modules/notifications/resolveFormMessage.js'
import { DEFAULT_DEVELOPMENT_HOSTS, isDevelopmentHost, matchDevelopmentHost } from '../src/modules/shared/developmentHosts.js'
import { setRateLimitStore } from '../src/modules/shared/rateLimit.js'
import { callConfirmRoute, relayPayload, relaySite } from './mailRelay/helpers.js'
@@ -711,19 +712,25 @@ describe('the token over time', () => {
})
// The owner's sites: built and enrolled on a development address, then launched on the real domain. A
// development or staging site says so itself (IAPL_NOINDEX=1, or a host in mail.relay.developmentHosts).
const DEV = 'acme.dev.agency-example.com'
const DEV_HOSTS = { developmentHosts: ['*.dev.agency-example.com'] }
// development address is known by its host: the built-in pattern `*.dev.netscale.pl`, with NO environment
// variable and no option (every test here runs with IAPL_NOINDEX empty unless it says otherwise).
const DEV = 'acme.dev.netscale.pl'
const DEV_HOSTS = {}
const AGENCY = { developmentHosts: ['*.dev.agency-example.com'] }
test('before launch: the site on its development address, with an empty store, enrols and sends by itself', async () => {
const dev = shared({ options: DEV_HOSTS, serverURL: `https://${DEV}` })
expect(process.env.IAPL_NOINDEX).toBe('')
expect(siteIsNonPublic(dev.payload, dev.options)).toBe(true)
expect(siteNonPublicSignal(dev.payload, dev.options)).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
expect(await mailPanelState({ payload: dev.payload }, dev.options)).toMatchObject({ nonPublic: true, nonPublicBy: 'development-host', nonPublicPattern: '*.dev.netscale.pl' })
expect((await sendThroughRelay(dev.payload, dev.options, MESSAGE)).sent).toBe(true)
expect(dev.fake.outbox[0].host).toBe(DEV)
// the same with the switch such a site already has, and no option at all
vi.stubEnv('IAPL_NOINDEX', '1')
const noindex = relaySite({ fake: { allow: [HOST] } })
expect(siteIsNonPublic(noindex.payload, noindex.options)).toBe(true)
expect(siteNonPublicSignal(noindex.payload, noindex.options)).toEqual({ by: 'noindex' })
expect(await mailPanelState({ payload: noindex.payload }, noindex.options)).toMatchObject({ nonPublic: true, nonPublicBy: 'noindex' })
expect((await sendThroughRelay(noindex.payload, noindex.options, MESSAGE)).sent).toBe(true)
})
@@ -849,6 +856,60 @@ describe('the token over time', () => {
expect((await readRelayStore(production.payload)).token).toBe(token)
})
test('the development pattern is a default a project can replace or empty — the plugin option, the mail option, the matcher', async () => {
const at = (serverURL: string, custom?: object, own: Parameters<typeof resolveRelayOptions>[1] = {}) => {
const site = relayPayload({ custom, serverURL })
return siteNonPublicSignal(site.payload, resolveRelayOptions(site.payload, own)!)
}
// built in: Intecion's development domain, any depth, any case, with a port; nothing that merely looks like it
expect(DEFAULT_DEVELOPMENT_HOSTS).toEqual(['*.dev.netscale.pl'])
expect(at('https://acme.dev.netscale.pl')).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
expect(at('https://WWW.Acme.dev.netscale.pl:8443/pl')).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
for (const url of ['https://client.pl', 'https://dev.netscale.pl', 'https://acme.dev.netscale.pl.evil.example', 'https://acme-dev.netscale.pl', 'https://netscale.pl', 'http://localhost:3000']) {expect(at(url)).toBeNull()}
// iapl({ developmentHosts }) replaces the list…
const own = { iapl: { developmentHosts: ['*.preview.agency-example.com', 'staging.client.pl'] } }
expect(at('https://x.preview.agency-example.com', own)).toEqual({ by: 'development-host', pattern: '*.preview.agency-example.com' })
expect(at('https://staging.client.pl', own)).toEqual({ by: 'development-host', pattern: 'staging.client.pl' })
expect(at('https://acme.dev.netscale.pl', own)).toBeNull()
expect(pluginDevelopmentHosts(relayPayload({ custom: own }).payload)).toEqual(own.iapl.developmentHosts)
// …`[]` empties it (the project's choice: then only IAPL_NOINDEX marks a copy)…
expect(at('https://acme.dev.netscale.pl', { iapl: { developmentHosts: [] } })).toBeNull()
// …and mail.relay.developmentHosts wins for the mail service
expect(at('https://acme.dev.netscale.pl', own, { developmentHosts: ['acme.*'] })).toEqual({ by: 'development-host', pattern: 'acme.*' })
expect(at('https://acme.dev.netscale.pl', undefined, { developmentHosts: [] })).toBeNull()
// either signal is enough; the host is named first
vi.stubEnv('IAPL_NOINDEX', '1')
expect(at('https://client.pl')).toEqual({ by: 'noindex' })
expect(at('https://acme.dev.netscale.pl')).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
vi.stubEnv('IAPL_NOINDEX', '')
// the matcher alone
expect(matchDevelopmentHost('https://a.dev.netscale.pl/x')).toBe('*.dev.netscale.pl')
expect(isDevelopmentHost('a.b.dev.netscale.pl')).toBe(true)
expect(isDevelopmentHost('a.dev.netscale.pl', [])).toBe(false)
expect(isDevelopmentHost('', ['*'])).toBe(false)
expect(matchDevelopmentHost('x.example.com', [' ', '*.Example.com '])).toBe('*.Example.com ')
// what emptying the list means: production's data on the development address is then a "launch", and sends
const live = shared({ serverURL: 'https://client.pl' })
await sendThroughRelay(live.payload, live.options, MESSAGE)
const copy = live.another(`https://${DEV}`)
expect(await sendThroughRelay(copy.payload, copy.options, MESSAGE)).toMatchObject({ cause: 'client-other-host', sent: false })
expect((await sendThroughRelay(copy.payload, { ...copy.options, developmentHosts: [] }, MESSAGE)).sent).toBe(true)
})
test('a developer\'s `localhost` on the production database, no env: refused before any call, nothing written', async () => {
const production = shared({ serverURL: 'https://client.pl' })
await sendThroughRelay(production.payload, production.options, MESSAGE)
const before = everything(production.store)
const requests = production.fake.requests.length
const local = production.another('http://localhost:3000')
const real = { ...local.options, ownUrl: false }
expect(siteNonPublicSignal(local.payload, real)).toBeNull()
expect(await sendThroughRelay(local.payload, real, { ...MESSAGE, to: '[email protected]' })).toMatchObject({ cause: 'host-not-allowed', code: 'relay-refused', sent: false })
expect(production.fake.requests).toHaveLength(requests)
expect(everything(production.store)).toBe(before)
})
test('`www` and the bare domain are one site, also for a non-public one: neither holds the other', async () => {
const apex = shared({ options: DEV_HOSTS, serverURL: `https://${DEV}` })
const www = apex.another(`https://www.${DEV}`, DEV_HOSTS)
@@ -893,10 +954,10 @@ describe('the token over time', () => {
expect((await sendThroughRelay(waiting.payload, named, MESSAGE)).sent).toBe(true)
expect((await readRelayStore(waiting.payload, 'example.net')).refusal).toBeFalsy()
// a non-public copy with 'enrol': the project took the rule away
const any = old.another('https://copy.dev.agency-example.com', { ...DEV_HOSTS, otherHosts: 'enrol' })
const any = old.another('https://copy.dev.agency-example.com', { ...AGENCY, otherHosts: 'enrol' })
expect((await sendThroughRelay(any.payload, any.options, MESSAGE)).sent).toBe(true)
// a non-public copy that names SOME hosts as its own still stops for the others
const partly = old.another('https://two.dev.agency-example.com', { ...DEV_HOSTS, otherHosts: ['example.com'] })
const partly = old.another('https://two.dev.agency-example.com', { ...AGENCY, otherHosts: ['example.com'] })
expect(await sendThroughRelay(partly.payload, partly.options, MESSAGE)).toMatchObject({ cause: 'client-other-host', sent: false })
// …the panel shows that refusal from the store, and drops it the moment its reason is gone (no send needed)
expect((await mailPanelState({ payload: partly.payload }, partly.options)).relay?.refusal).toMatchObject({ code: 'client-other-host' })
+11
View File
@@ -4,6 +4,7 @@ import { describe, expect, test, vi } from 'vitest'
import type { I18nConfig } from '../src/modules/i18n/types.js'
import { pluginDevelopmentHosts } from '../src/modules/email/relay/options.js'
import { iapl } from '../src/plugin.js'
import { withTotpParts } from './helpers.js'
@@ -22,6 +23,16 @@ const base = (): Config =>
}) as unknown as Config
describe('iapl — config transform', () => {
test('developmentHosts: nothing in the config by default (the built-in list applies), the project\'s list when given, an empty list too', async () => {
const hosts = async (own?: string[]) => {
const config = await iapl({ access: { authCollection: 'users' }, i18n, twoFactor: false, ...(own ? { developmentHosts: own } : {}) })(base())
return pluginDevelopmentHosts({ config } as never)
}
expect(await hosts()).toEqual(['*.dev.netscale.pl'])
expect(await hosts(['*.preview.agency-example.com'])).toEqual(['*.preview.agency-example.com'])
expect(await hosts([])).toEqual([])
})
test('adds globals, endpoint, localization and roles', async () => {
const config = await iapl({ access: { authCollection: 'users' }, i18n, twoFactor: false })(base())