Dev.to AI 🤖 Ai 👁 0 📖 8 min read

Embedding Securely: Where the Real Security Boundary Is in ByteChef Embedded

You've wired an automation platform into your SaaS: iframes in your UI, signed tokens in the browser, backend API calls, and an MCP endpoint for AI agents. Every one of those is a door into your customers' data. So where

Embedding Securely: Where the Real Security Boundary Is in ByteChef Embedded

You've wired an automation platform into your SaaS: iframes in your UI, signed tokens in the browser, backend API calls, and an MCP endpoint for AI agents. Every one of those is a door into your customers' data. So where exactly is the lock?

This post walks through the security boundary of ByteChef Embedded and sorts every control into three buckets: what the server enforces, what the UI only hides, and what's left to you. The good news: most of it is on by default. You have two settings to flip and a handful of sample-app shortcuts to fix before real users show up.

TL;DR

  • Your backend signs a short-lived RS256 JWT per user. ByteChef verifies it on every request and treats sub as the user.
  • A token works for one user in one environment. Nothing else.
  • Set BYTECHEF_EMBEDDED_ALLOWED_PARENT_ORIGINS so only your app can frame the embedded pages.
  • Turn on the audit log with BYTECHEF_AUDIT_ENABLED=true.
  • Rate limiting is your job.

The boundary on one screen

Layer Enforced by You configure
Who the user is JWT signature vs. your Signing Key One key per environment, short TTL
Whose data sub must match the path; frontend endpoints read the user from the token Nothing
Which environment Keys, users and MCP servers each belong to one X-Environment header, optional environmentId claim
Who can frame the UI frame-ancestors CSP + origin-checked handshake BYTECHEF_EMBEDDED_ALLOWED_PARENT_ORIGINS
Admin operations Tenant-admin check on every call Who gets the admin role
What an agent can call Server-wide and per-user MCP tool switches Your MCP servers
Credentials at rest AES-GCM encryption Encryption key provider
Evidence Audit events bytechef.audit.enabled
Volume Nothing Rate limits at your ingress

1. Identity: one signed token per user

Your users never get ByteChef accounts. Your backend vouches for them with a signed JWT, and ByteChef trusts the signature, not the browser.

Create a key under Embedded → Settings → Signing Keys. ByteChef generates an RSA-2048 pair, stores the public half with a Key Id (your kid), and shows you the private key once. Lose it and you create a new one.

The Signing Keys page listing two keys with Name, Key Id, Created Date and Last Used Date

Minting a token on your backend looks like this:

import jwt from 'jsonwebtoken';

export function signConnectedUserToken(userId: string): string {
  return jwt.sign(
    {
      sub: userId,                   // your user's stable id
      environmentId: 2,              // optional: pin to PRODUCTION
      connectionDialogAllowed: true, // optional: may they create connections?
    },
    process.env.BYTECHEF_PRIVATE_KEY!,
    { algorithm: 'RS256', expiresIn: '10m', keyid: process.env.BYTECHEF_KID! }
  );
}

What ByteChef checks before any endpoint runs:

  • kid is required and must exist in the request's environment, or you get a 401.
  • Signature is verified against the stored public key.
  • exp is honored, but not required. Always set it.
  • sub is required and decides whose data the request touches. The first request for a new sub creates the user.
  • environmentId, if present, must match the request's environment.
  • name, email, anything else is ignored. Profile data comes from the admin UI, a CSV import or a PATCH call.

If the check itself can't run (say, the database is down), you get a 503, never a silent pass.

Rotation is deliberately boring: create a new key, deploy it, delete the old one. With a 10-minute TTL and a frontend that refreshes on 401, nobody notices.

2. Two credentials that never overlap

Connected-user JWT Embedded API Key
Lives in The browser, for minutes Your backend
Used on /automation/workflows, /connections, ... /{externalUserId}/automation/workflows, ...
The user is The token's sub The path segment

Two rules make this safe:

  • A JWT acts only for itself. If sub doesn't match {externalUserId}, it's a 401 before the endpoint runs. A token for user 1234 can't touch user 5678.
  • An API Key never acts as a browser. Keys are rejected on frontend paths, and must be an Embedded key from the same environment.

3. Environments are separate worlds

Every request lives in exactly one environment, picked by the X-Environment header. No header means PRODUCTION.

The environment selector offering DEVELOPMENT, STAGING and PRODUCTION

User 1234 in Development and user 1234 in Production are two different users with different connections and workflows. This also explains the most confusing 401 in development: a token signed with a Development key, sent without the header, gets checked against Production keys.

4. Lock the frame

The workflow builder, Automation Hub and Integration Marketplace render in your product as iframes. Left open, any site could frame them, which is exactly what clickjacking needs.

BYTECHEF_EMBEDDED_ALLOWED_PARENT_ORIGINS=https://app.example.com,https://admin.example.com

Once set (and the server restarted), those pages send Content-Security-Policy: frame-ancestors ... and accept their init message only from the listed origins. Everything else in the ByteChef UI sends X-Frame-Options: DENY regardless.

Gotcha: use exact origins, no wildcards. A browser would accept https://*.example.com in frame-ancestors, but the handshake compares origins exactly, so the page renders and then never initializes.

With the list empty, every embedded page logs a console warning. Production shouldn't show it.

The handshake checks both ways

The iframe posts EMBED_READY only to allowed origins and accepts EMBED_INIT only from its direct parent. On your side, the @bytechef/embedded components only talk to the origin of the baseUrl you passed. The JWT rides inside EMBED_INIT, never in the URL, so it stays out of history, Referer headers and access logs, and it's kept in memory, never in local storage.

5. Enforced vs. merely hidden

This is the table to remember when someone opens devtools:

Control Server-enforced?
connectionDialogAllowed claim ✅ false means creating a connection is a 403
connectionDialogAllowed prop Only as a restriction; it can't grant what the token denies
includeComponents, tabs, editWorkflowAllowed ❌ UI only
Enabled integration configurations ✅
Shared connections ✅ only the owner can reconnect or delete
Permission expressions Evaluated server-side, but on data the user can edit

That last row bites people. A user holding their own JWT can PATCH /api/embedded/v1/me and change their own name, email and metadata. So metadata.plan == 'enterprise' is fine for tidying a catalog and useless for protecting anything. Restrict real features with things the user can't edit: which configurations you enable, which tokens you mint, what your backend allows.

6. CORS, CSRF and sessions

Embedded auth is a bearer header, never a cookie, so there's nothing for CSRF to ride on and no server session to hijack. Many embedded endpoints allow cross-origin calls from anywhere, and that's fine: CORS isn't access control, the token is. The admin UI does use a session cookie and keeps its XSRF protection.

7. Admin side: tenant admins only

Well over a hundred embedded admin operations (integrations, MCP servers, connected users, Signing Keys...) require ROLE_ADMIN. A connected user's token carries no roles, so it can never pass that check. Keep the admin group small: any admin can manage every key in the environment.

8. MCP: who can switch what

The embedded MCP URL looks like https://<your-bytechef>/api/embedded/{secretKey}/mcp. The URL routes, the token authenticates: every call also needs a connected-user JWT, or it's a 401 before a single tool is listed.

Tools have two layers of switches:

  • Server-wide (admin): off means not listed and not callable, period. New tools start on, so review the list after adding a component.
  • Per user: tools start off and users enable them on their own instances. An admin can flip a user's switch, but the user can flip it back. For anything that must stay off, use the server-wide switch.

An MCP server's Component Tools tab with an enable toggle and a switch per Gmail tool

One heads-up: a connection_required result contains a setupUrl with a signed, 10-minute token in the query string. It's the one place a token travels in a URL, so don't log tool results verbatim.

9. Credentials at rest and the audit trail

Connection secrets are encrypted with AES-GCM and a fresh IV per value, and never returned over the wire. The default FILESYSTEM provider keeps the key in ~/.bytechef/key. For containers or multiple replicas, switch to BYTECHEF_ENCRYPTION_PROVIDER=PROPERTY and share the same key everywhere. Back it up with your database, or stored credentials are gone.

The audit log is off by default. Turn it on:

BYTECHEF_AUDIT_ENABLED=true

You'll get events for Signing Key changes, connection changes, connected-user changes, MCP tool switches, publishing, and authentication (AUTHENTICATION_FAILURE, plus deduplicated CREDENTIAL_USED). Retention defaults to 365 days.

10. Rate limiting is yours

ByteChef has no per-user or per-tenant rate limit. Data is isolated; throughput isn't. Put limits where you know the customer: your gateway, your token endpoint, App Event bursts, and expensive operations like workflow generation.

Fix these in the sample app

The embedded sample app is built to run in five minutes, not to face the internet:

  • POST /api/token signs for any user id in the request body. Derive sub from your own session. Never trust a user id from the browser.
  • CORS is origin: '*'. Allow only your frontend, or serve the token route same-origin.
  • TTL defaults to 1h. Ten minutes is plenty.
  • The token cache is a module variable used from server components, so it's shared across requests. Key it by user.
  • connectionDialogAllowed={true} is only a prop. Set the claim in the token for users who shouldn't create connections.

ByteChef runs the checks, but the signature is only as strong as the rule that decides who gets a token.

Production checklist

  • [ ] One Signing Key per environment; private key is a backend secret
  • [ ] Tokens minted from your authenticated session, exp ≈ 10 min
  • [ ] environmentId and connectionDialogAllowed set where needed
  • [ ] API Keys only on the backend, one per environment
  • [ ] X-Environment sent explicitly on every call
  • [ ] BYTECHEF_EMBEDDED_ALLOWED_PARENT_ORIGINS set to exact origins
  • [ ] UI props and permission expressions treated as presentation, not security
  • [ ] Admin group kept small
  • [ ] MCP servers keep auth on; tool list reviewed after each new component
  • [ ] BYTECHEF_ENCRYPTION_PROVIDER=PROPERTY with a backed-up key on multi-instance setups
  • [ ] BYTECHEF_AUDIT_ENABLED=true
  • [ ] Rate limits at your ingress and token endpoint
  • [ ] Logs never capture Authorization headers, EMBED_INIT payloads or connection_required links

Try it

Set BYTECHEF_EMBEDDED_ALLOWED_PARENT_ORIGINS to your local sample app's origin, restart ByteChef, then frame the Automation Hub from a page on another port and watch the browser refuse it. Send a request with another user's id in the path and enjoy the 401.

This is part 17 of the ByteChef Embedded series. The full version, with every detail and the rest of the series, is on the ByteChef blog. Questions about embedding securely? Drop them in the comments.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.