Skip to content

External Submission Endpoint for Untrusted-Origin Pages

  • Deciders: Julian Bäume
  • Date: 2026-06-19
  • Status: Accepted

Status

Accepted

Context

Static or external web pages — feedback widgets, contact forms, and external forms in general — need to create a thread in a designated Teams inbox directly from the visitor's browser, on a different origin from Teams.

Thread creation is a pure DB insert into threads + actions — no mail, Dovecot, or token exchange (threads.ts:920-955). A submission therefore needs no mail identity, which is what makes an unattributed (anonymous) thread possible at all.

Teams already has a narrow precursor: a membership bypass for one operator-chosen inbox (FEEDBACK_INBOX_ID), always attributed to the authenticated user. It covers a single same-origin case and cannot express anonymity, multiple target inboxes, external issuers, or application callers. The capability below subsumes it (see Consequences).

Forces

  • Must not become a public write API reachable by any anonymous script.
  • Must allow both attributed and anonymous submissions.
  • Must be reusable across form types and target inboxes, not hard-wired to one.
  • Must resist abuse on a now internet-reachable write path.
  • Must never let a client assert an OX identity (id/context).
  • External input is untrusted and must not become a stored-XSS vector when the triage team opens the thread in Teams — note the comment view renders the stored message via v-html, so the stored value must be safe by construction.

Options considered

1. How is the caller authenticated?

  • A. Origin allowlist only (CORS). Rejected. CORS is browser-enforced and exists to protect a user's credentials from other sites; a non-browser client ignores it and forges the Origin header. This leaves a public write API.
  • B. A dedicated shared service account. One credential used by the calling page or its backend. Works, but a single long-lived secret with a broad blast radius and no per-submitter principal for attribution.
  • C. Any valid token from a trusted issuer. Require a JWT that passes the SDK's existing issuer/signature/expiry checks, but drop the user-scope requirement on this route. This admits both a user token and an application (client-credentials) token — they differ only in whether a user identity is present, which is also what decides attribution. CORS stays as an origin hint, not the gate.

Decision: C. The token is the boundary; user-vs-application is the caller's choice. Optionally pin the token's azp/aud to an accepted-client allowlist so "valid token from the realm" does not mean "anyone with an account".

The shared /api auth hook normally also requires OX user claims (userId, email) and, in popup mode, a Teams session. External principals have neither, so this route opts into a dedicated auth path (externalAuth route config): the token is still verified (issuer + signature), but the OX-claim and session checks are skipped. Authorization is then the route's own (inbox allowlist + client pin), and attribution falls back to whatever claims are present (or none).

2. How is the endpoint shaped?

  • A. Reuse PUT /:inboxId. Smallest change, but forces global CORS to allow PUT for every route and tangles relaxed auth + rate limiting into the member-posting path.
  • B. Dedicated sub-route POST /api/threads/:inboxId/submissions. Uses the already-allowed POST method (no global CORS change) and isolates the relaxed auth, rate limiting, and length caps to one path.
  • C. New top-level resource (/api/submissions). Cleanest URL, but splits thread creation across two route trees for no real gain.

Decision: B.

3. How is authorship represented?

OX identity (id/context) is never accepted from a client — that is impersonation. Contact info (free-text name/email) is just content, like an email From: line. Three modes:

  • from omitted → authenticated: derive email + display name from token claims; verified: true. (External users carry no OX id/context; only email/name are stored.)
  • from: null → anonymous: store a language-neutral sentinel (displayName: "Anonymous", email: "") with action.data.from = null; the UI localizes the label.
  • from: { displayName, email } → declared: the submitter's self-provided contact, stored verified: false and badged "external" in the UI. email is optional and may be empty; it is not format-validated (ownership is unverified anyway, and a contact form should not reject a missing address at the API).

Decision: all three. They are independent of authentication: anonymity and self-declared contact are attribution choices, not auth states.

Decision

Add POST /api/threads/:inboxId/submissions:

  • Authenticated by any valid trusted-issuer token (user or application); the user scope is not required. Optional accepted-client pin via azp/aud.
  • Authorized against an inbox allowlist — the target inbox must be listed and must exist; all other inboxes keep enforcing membership.
  • Authorship per the three modes above; id/context never persisted.
  • message is Markdown, rendered to HTML on the server with markdown-it configured html: false — raw HTML in the source is escaped, not emitted, so the v-html comment renderer cannot run injected markup. The rendered HTML is stored; the list preview still strips tags to plain text. Inline images and attachments remain deferred to a later feature (see Follow-up).
  • Rate-limited per principal (IP fallback).

Defaults (all configurable): 2 requests/minute per principal; subject ≤ 200 chars; message ≤ 5000 chars of Markdown source; a modest request-body cap as a backstop. Sized for a human filling in a form — room to tell a story, not to paste a book.

Structured caller context (e.g. a rating or a slug) is not part of v1 — it has no consumer in the Teams UI yet, so callers fold any context into message. A typed metadata field can be added later together with a way to display it.

Operator configuration (no code; documented):

VariablePurpose
EXTERNAL_SUBMISSION_INBOX_IDSInbox ids accepting submissions. Unset = dormant.
EXTERNAL_SUBMISSION_CLIENTSOptional accepted azp/client_id allowlist.
ISSUER_ALLOWLISTAdd the external issuer so its tokens validate (widens trust globally; other routes stay gated by their own checks).
ORIGINSSet to a real allowlist (not *) when enabled.

See External Submission for the contract, scenarios, and acceptance criteria.

Consequences

Positive

  • One capability covers feedback, contact, and future external forms.
  • Authentication is a real boundary, not a forgeable origin header.
  • Anonymity and self-declared contact are first-class, caller-controlled choices.
  • Relaxed auth is confined to one narrow route.

Negative

  • Adding an external issuer widens token trust globally (contained by per-route scope + membership checks; a deliberate operator action).
  • New runtime dependency (@fastify/rate-limit) and a trustProxy requirement.

Follow-up

  • Inline images and dedicated attachments for external submissions are deferred to a later feature; v1 accepts Markdown text only (no images/attachments).

Security

  • Bypass scoped to the allowlist; all other inboxes enforce membership.
  • Client-asserted OX identity is never persisted; declared contacts are flagged unverified.
  • message is rendered from Markdown with raw HTML disabled (html: false), so an external submission cannot inject script that the v-html view would run.
  • Rate limiting + length/body caps bound the abuse surface.

References