BossaMotion login and corporate-domain access policy. Upstream AGPL-3.0-only: https://github.com/agentes-chat/agentes-chat/tree/4eef34921da111a08f80ba8b5fc022b7dce43cb5 Figma: https://www.figma.com/design/YKXD1wpUbnLXzNtsrQHHLq?node-id=91-3 Backend sources: /bossa-login/backend/guard.ts, bootstrap.ts, guard.test.ts. Bootstrap: bun build bootstrap.ts --target=bun --minify --external /app/apps/server/src/main.ts --outfile bootstrap.mjs; then run bun bootstrap.mjs in the official 0.1.20 image, retaining the official environment and volumes. --- index.js --- const publicHost = "agentschat.bossamotion.ai"; const previousHost = "chat.bossamotion.ai"; const brandPanel = ``; export default { async fetch(request, env) { const url = new URL(request.url); if (url.hostname === previousHost) { url.hostname = publicHost; return Response.redirect(url.toString(), 308); } if (url.hostname !== publicHost) return new Response(null, { status: 404 }); if (url.pathname.startsWith("/bossa-login/")) return env.ASSETS.fetch(request); url.hostname = "srv2117987.hstgr.cloud"; const upstream = new Request(url, request); upstream.headers.set("X-Bossa-Service", "agentes-chat"); upstream.headers.set("X-Forwarded-Host", publicHost); upstream.headers.set("X-Forwarded-Proto", "https"); const response = await fetch(upstream, {redirect: "manual", cache: "no-store"}); if (response.status === 101) return response; const result = new Response(response.body, response); result.headers.set("Cache-Control", "private, no-store"); if (!result.headers.get("content-type")?.includes("text/html")) return result; return new HTMLRewriter() .on("head", { element(el) { el.prepend('', { html: true }); } }) .on("title", { element(el) { el.setInnerContent("AgentsChat · BossaMotion"); } }) .on('link[rel="icon"]', { element(el) { el.setAttribute("href", "/bossa-login/icon.svg"); el.setAttribute("type", "image/svg+xml"); } }) .on("body", { element(el) { el.append(brandPanel, { html: true }); } }) .transform(result); } }; --- public/bossa-login/brand.css --- /* BossaMotion.ai Figma 91:3: official login composition and design tokens. */ @font-face{font-family:BossaGeist;src:url('./geist.ttf') format('truetype');font-weight:100 900;font-display:swap} @font-face{font-family:BossaSerif;src:url('./instrument-serif.ttf') format('truetype');font-weight:400;font-display:swap} @font-face{font-family:BossaMono;src:url('./geist-mono.woff2') format('woff2');font-weight:400 600;font-display:swap} .bossa-identity,.bossa-attribution{display:none} body:has(.auth){background:#f5f2eb!important;color:#0e0f12;--font-sans:BossaGeist,system-ui,sans-serif} body:has(.auth) .bossa-identity{box-sizing:border-box;display:flex;position:fixed;inset:0 auto 0 0;width:55.5556%;padding:72px clamp(40px,5.5556vw,110px);background:#0e0f12;color:#f5f2eb;flex-direction:column;justify-content:space-between;z-index:1;font-family:BossaGeist,system-ui,sans-serif} .bossa-logo{display:block;width:187px;height:40px;flex:none} .bossa-logo img{display:block;width:100%;height:100%} .bossa-message{margin:auto 0;max-width:640px;padding:48px 0} .bossa-kicker{margin:0 0 30px;color:#d7f24a;font:500 13px/1.4 BossaMono,monospace;letter-spacing:.08em} .bossa-message h2{font:400 clamp(52px,5.28vw,92px)/1 BossaSerif,Georgia,serif;letter-spacing:-.02em;margin:0;text-wrap:balance} .bossa-message h2 em{color:#d7f24a;font-weight:400} .bossa-description{color:#92959c;font:400 18px/1.5 BossaGeist,system-ui,sans-serif;margin:30px 0 0;max-width:570px;text-wrap:pretty} .bossa-bottom{display:flex;align-items:center;gap:12px;color:#898d96;font:400 12px/1.4 BossaMono,monospace;flex-wrap:wrap} .bossa-dots{display:flex;gap:10px} .bossa-dots i{width:8px;height:8px;background:#f5f2eb;border-radius:50%} .bossa-dots i:first-child{background:#d7f24a} body:has(.auth) .auth{box-sizing:border-box;min-height:100vh;min-height:100dvh;width:44.4444%;margin-left:55.5556%;padding:100px clamp(28px,6.6667vw,110px) 110px;display:flex;align-items:center;justify-content:center;background:#f5f2eb!important;color:#0e0f12;font-family:BossaGeist,system-ui,sans-serif;--bg:#f5f2eb;--ink:#0e0f12;--muted:#52565f;--faint:#6b6e75;--line:#ccc8bf;--surface:#fff;--surface-raised:#fff;--surface-sunken:#eae7df;--agent:#2d3fe0;--accent:#2d3fe0} body:has(.auth) .auth__horizon,body:has(.auth) .auth__logo,body:has(.auth) .auth__ask>.ac-avatar{display:none!important} body:has(.auth) .auth__lang{position:fixed;right:24px;top:24px;z-index:3;color:#0e0f12} body:has(.auth) .auth__col{max-width:448px;width:100%;margin:auto 0} body:has(.auth) .auth__col::before{content:'ENTRAR';display:block;margin:0 0 28px;color:#2d3fe0;font:500 13px/1.4 BossaMono,monospace;letter-spacing:.08em} body:has(.auth) .auth__form{gap:28px} body:has(.auth input[autocomplete="new-password"]) .auth__col::before{content:'PRIMEIRO ACESSO'} body:has(.auth) .auth__ask{gap:0} body:has(.auth) .auth__bubble{padding:0;background:none!important;border:0;border-radius:0;box-shadow:none!important} body:has(.auth) .auth__title{font:400 48px/1.05 BossaSerif,Georgia,serif;letter-spacing:0;text-wrap:balance;color:#0e0f12} body:has(.auth) .auth__lead{margin:24px 0 0;font:400 16px/1.5 BossaGeist,system-ui,sans-serif;color:#454952;overflow-wrap:anywhere} body:has(.auth) .auth__step{gap:16px} body:has(.auth) .auth__big.ac-input{box-sizing:border-box;height:60px;min-height:60px;background:#fff!important;color:#0e0f12!important;border:1px solid #c8c5be!important;border-radius:14px!important;box-shadow:none!important;padding-left:21px;font:400 16px/1.4 BossaGeist,system-ui,sans-serif} body:has(.auth) .auth__big.ac-input:focus{outline:2px solid #2d3fe0;outline-offset:3px} body:has(.auth) .ac-btn--primary{min-height:44px;background:#0e0f12!important;color:#f5f2eb!important;border:1px solid #0e0f12!important;border-radius:999px!important;font-family:BossaGeist,system-ui,sans-serif;box-shadow:none!important} body:has(.auth) .ac-btn--primary:hover:not(:disabled){background:#2d3fe0!important;border-color:#2d3fe0!important} body:has(.auth) .ac-btn:focus-visible,body:has(.auth) a:focus-visible{outline:2px solid #2d3fe0;outline-offset:4px} body:has(.auth) .auth__fine,body:has(.auth) .auth__quiet{font-family:BossaGeist,system-ui,sans-serif;color:#52565f} body:has(.auth) .bossa-attribution{display:block;position:fixed;bottom:28px;left:55.5556%;right:0;padding:0 24px;text-align:center;font:400 11px/1.7 BossaGeist,system-ui,sans-serif;color:#6b6e75;z-index:2} .bossa-attribution a{color:inherit;text-decoration:underline;text-underline-offset:3px} @media(min-width:1800px){body:has(.auth) .bossa-identity{padding-top:9vh;padding-bottom:9vh}} @media(max-width:1000px) and (min-width:761px){body:has(.auth) .bossa-identity{padding:48px 36px;width:48%}body:has(.auth) .auth{width:52%;margin-left:48%;padding-left:36px;padding-right:36px}body:has(.auth) .bossa-attribution{left:48%}.bossa-message h2{font-size:58px}.bossa-description{font-size:16px}} @media(max-width:760px){body:has(.auth) .bossa-identity{position:relative;inset:auto;width:100%;padding:32px 24px;min-height:250px;gap:24px}.bossa-logo{width:164px;height:auto;aspect-ratio:187/40}.bossa-message{padding:0;margin:0}.bossa-kicker{font-size:10px;margin-bottom:14px}.bossa-message h2{font-size:46px;line-height:1.02;max-width:520px}.bossa-description,.bossa-bottom{display:none}body:has(.auth){display:flex;flex-direction:column}body:has(.auth) #root{order:2;flex:1}body:has(.auth) .bossa-identity{order:1}body:has(.auth) .auth{width:100%;margin:0;min-height:0;padding:44px 24px 40px;align-items:flex-start}body:has(.auth) .auth__col{margin:0;max-width:520px}body:has(.auth) .auth__col::before{margin-bottom:20px;font-size:11px}body:has(.auth) .auth__title{font-size:38px}body:has(.auth) .auth__lead{margin-top:16px}body:has(.auth) .auth__lang{position:absolute;top:24px;right:16px;color:#f5f2eb}body:has(.auth) .bossa-attribution{position:static;order:3;padding:0 24px 24px}body:has(.auth) .auth__big.ac-input{height:56px;min-height:56px}} @media(prefers-reduced-motion:reduce){body:has(.auth) *{animation:none!important;transition:none!important}} --- public/bossa-login/init.js --- // Default to Portuguese on first visit; keep every later language choice. try { if (!localStorage.getItem("agentes.locale")) localStorage.setItem("agentes.locale", "pt-BR"); } catch {} // Friendly feedback complements the authoritative backend policy. document.addEventListener("input", (event) => { const input = event.target; if (input instanceof HTMLInputElement && input.type === "email" && input.closest(".auth")) input.setCustomValidity(""); }, true); document.addEventListener("submit", (event) => { const form = event.target; if (!(form instanceof HTMLFormElement) || !form.closest(".auth")) return; const input = form.querySelector('input[type="email"]'); if (!(input instanceof HTMLInputElement) || !input.value || /^[^@\s]+@bossamotion\.ai$/i.test(input.value)) return; event.preventDefault(); event.stopImmediatePropagation(); input.setCustomValidity("Use seu e-mail @bossamotion.ai para acessar a BossaMotion."); input.reportValidity(); }, true); // The app manages its own tab title; brand only the public access screens. document.addEventListener("DOMContentLoaded", () => { const title = document.querySelector("title"); if (!title) return; const refresh = () => { if (/^\/(login|owner|signup|reset-password)(\/|$)/.test(location.pathname) && document.title !== "AgentsChat · BossaMotion") document.title = "AgentsChat · BossaMotion"; }; new MutationObserver(refresh).observe(title, { childList: true, subtree: true }); refresh(); }); --- public/bossa-login/backend/guard.ts --- // SPDX-License-Identifier: AGPL-3.0-only import { plugin } from "bun"; /** An exact mailbox domain, not a substring, suffix or subdomain match. */ export function allowedEmail(email: unknown): email is string { return typeof email === "string" && /^[^@\s]+@bossamotion\.ai$/i.test(email); } const predicate = `const __bossaAllowedEmail = ${allowedEmail.toString()};\n`; const assertion = `function __bossaAssertEmail(email) { if (!__bossaAllowedEmail(email)) throw new APIError("FORBIDDEN", { code: "BOSSA_EMAIL_DOMAIN", message: "Acesso permitido somente com e-mail @bossamotion.ai." }); }\n`; function replaceOnce(source: string, marker: string, replacement: string): string { const count = source.split(marker).length - 1; if (count !== 1) throw new Error(`Bossa domain guard: unsupported upstream source (${count} matches): ${marker.slice(0, 75)}`); return source.replace(marker, replacement); } /** Patch fixed, explicit hook points; an incompatible upstream build fails closed. */ export function transform(path: string, original: string): string { let source = original; if (path.endsWith("/src/auth.ts")) { const signup = 'const assertSignupAllowed = async (email: string, access: string | null) => {'; source = replaceOnce(source, signup, signup + '\n __bossaAssertEmail(email);'); const before = 'before: createAuthMiddleware(async (ctx) => {'; source = replaceOnce(source, before, before + ` for (const key of ["email", "newEmail"]) { const value = ctx.body?.[key]; if (typeof value === "string") __bossaAssertEmail(value); }`); const update = 'update: {\n // Their name'; source = replaceOnce(source, update, `update: { before: async (user) => { if (user.email !== undefined) __bossaAssertEmail(user.email); }, // Their name`); const session = 'before: async (session) => {\n const block ='; source = replaceOnce(source, session, `before: async (session) => { const [bossaAccount] = await db.select({email: schema.users.email}).from(schema.users).where(eq(schema.users.id, session.userId)).limit(1); __bossaAssertEmail(bossaAccount?.email); const block =`); return predicate + assertion + source; } if (path.endsWith("/src/owner-claim.ts")) { const owner = 'async function createOwner(input: { id: string; name: string; email: string; passwordHash: string | null }) {'; source = replaceOnce(source, owner, owner + '\n __bossaAssertEmail(input.email);'); const claim = 'async (ctx) => {\n if (!config.OWNER_CLAIM_SHA256)'; source = replaceOnce(source, claim, 'async (ctx) => {\n __bossaAssertEmail(ctx.body.email);\n if (!config.OWNER_CLAIM_SHA256)'); return predicate + assertion + source; } if (path.endsWith("/src/routes/app/context.ts")) { source = replaceOnce(source, 'if (c.get("user")) return next();', `if (c.get("user")) { if (!__bossaAllowedEmail(c.get("user").email)) return apiError(c, 403, "BOSSA_EMAIL_DOMAIN", "Acesso permitido somente com e-mail @bossamotion.ai."); return next(); }`); const noSession = 'if (!user) return apiError(c, 401, "unauthorized", "Sign in to continue");'; source = replaceOnce(source, noSession, noSession + '\n if (!__bossaAllowedEmail(user.email)) return apiError(c, 403, "BOSSA_EMAIL_DOMAIN", "Acesso permitido somente com e-mail @bossamotion.ai.");'); return predicate + source; } if (path.endsWith("/src/routes/app/account.ts")) { const invite = 'const { invitation, token } = await createInvitation('; source = replaceOnce(source, invite, `const bossaInvitationEmail = c.req.valid("json").email; if (typeof bossaInvitationEmail === "string" && !__bossaAllowedEmail(bossaInvitationEmail)) return apiError(c, 403, "BOSSA_EMAIL_DOMAIN", "Convites somente para e-mails @bossamotion.ai."); const { invitation, token } = await createInvitation(`); return predicate + source; } throw new Error(`Bossa domain guard: unexpected module ${path}`); } export async function install(root = "/app/apps/server") { const paths = ["src/auth.ts", "src/owner-claim.ts", "src/routes/app/context.ts", "src/routes/app/account.ts"]; // Validate every hook before starting the upstream server, even when a module is loaded lazily. const contents = new Map(); for (const relative of paths) { const path = `${root}/${relative}`; contents.set(path, transform(path, await Bun.file(path).text())); } plugin({ name: "bossa-corporate-email-domain", setup(builder) { builder.onLoad({filter: /\/src\/(auth|owner-claim|routes\/app\/(context|account))\.ts$/}, ({path}) => { const source = contents.get(path); if (!source) throw new Error("Bossa domain guard: unexpected source root"); return {contents: source, loader: "ts"}; }); }, }); console.info("Bossa access policy active: exact @bossamotion.ai domain; signup, owner, sessions, email changes and invitations."); } --- public/bossa-login/backend/bootstrap.ts --- import { install } from "./guard"; await install(); await import("/app/apps/server/src/main.ts"); --- public/bossa-login/backend/guard.test.ts --- import { test, expect } from "bun:test"; import { allowedEmail, transform } from "./guard"; test("accepts only the exact corporate mailbox domain", () => { for (const email of ["hugo@bossamotion.ai", "Person+tag@BOSSAMOTION.AI"]) expect(allowedEmail(email)).toBe(true); for (const email of ["hugo@gmail.com", "hugo@sub.bossamotion.ai", "hugo@bossamotion.ai.evil.test", "hugo@evilbossamotion.ai", "bossamotion.ai@evil.test", "hugo@bossamotion.ai ", "hugo@bossamotion.ai\n", "a@b@bossamotion.ai", "@bossamotion.ai", null, {}]) expect(allowedEmail(email)).toBe(false); }); test("upstream changes cannot silently remove the security hooks", () => { expect(() => transform("/app/apps/server/src/auth.ts", "export const changed = true")).toThrow("unsupported upstream"); expect(() => transform("/unrelated.ts", "")).toThrow("unexpected module"); }); test("all four real upstream modules keep valid TypeScript after interception", async () => { const root = process.env.AGENTES_SOURCE ?? "/tmp/agentes-chat-source/apps/server"; const transpiler = new Bun.Transpiler({loader:"ts",target:"bun"}); for (const path of ["src/auth.ts", "src/owner-claim.ts", "src/routes/app/context.ts", "src/routes/app/account.ts"]) { const source = transform(`${root}/${path}`, await Bun.file(`${root}/${path}`).text()); expect(() => transpiler.transformSync(source)).not.toThrow(); } }); test("the actual upstream session middleware rejects external users, including cached sessions", async () => { const path = (process.env.AGENTES_SOURCE ?? "/tmp/agentes-chat-source/apps/server") + "/src/routes/app/context.ts"; const patched = transform(path, await Bun.file(path).text()); const start = patched.indexOf("export function requireSession("); const end = patched.indexOf("/**", start); const middleware = patched.slice(start, end).replace("export function", "function"); const predicate = patched.slice(0, patched.indexOf("\nimport ")); const js = new Bun.Transpiler({loader:"ts"}).transformSync(predicate + middleware); for (const cached of [false, true]) { for (const email of ["person@bossamotion.ai", "person@outside.example"]) { let passed = false; const person = {email}; const factory = new Function("createMiddleware", "sessionUser", "apiError", js + ";return requireSession;"); const requireSession = factory((fn: unknown) => fn, async () => person, (_c: unknown, status: number, code: string) => Response.json({code},{status})); const context = {get: () => cached ? person : undefined, set: () => {}, req:{raw:{headers:new Headers()}}}; const response = await requireSession({})(context, async () => {passed = true;}); expect(passed).toBe(email.endsWith("@bossamotion.ai")); if (!passed) expect(response.status).toBe(403); } } }); --- wrangler.jsonc --- { "name": "bossa-agentes-chat-access", "main": "index.js", "account_id": "8377825e97c4f7373ce79e899a5c9103", "compatibility_date": "2026-12-01", "workers_dev": false, "preview_urls": false, "routes": [{"pattern": "agentschat.bossamotion.ai", "custom_domain": true}, {"pattern": "chat.bossamotion.ai", "custom_domain": true}], "assets": {"directory": "./public", "binding": "ASSETS", "run_worker_first": true} }