Skip to content

The open-source app everyone uses to manage agents at work

Prefer public base URL for generated invite links (#7619)

dmndbrp-ossa8d118a779ac
diff --git a/scripts/run-vitest-stable.mjs b/scripts/run-vitest-stable.mjs
index d8b334e58f..b77c9d8a38 100644
--- a/scripts/run-vitest-stable.mjs
+++ b/scripts/run-vitest-stable.mjs
@@ -48,6 +48,7 @@ const additionalSerializedServerTests = new Set([
"server/src/__tests__/invite-expiry.test.ts",
"server/src/__tests__/invite-join-manager.test.ts",
"server/src/__tests__/invite-onboarding-text.test.ts",
+ "server/src/__tests__/invite-url-public-base-url.test.ts",
"server/src/__tests__/issues-checkout-wakeup.test.ts",
"server/src/__tests__/issues-service.test.ts",
"server/src/__tests__/opencode-local-adapter-environment.test.ts",
diff --git a/server/src/__tests__/invite-url-public-base-url.test.ts b/server/src/__tests__/invite-url-public-base-url.test.ts
new file mode 100644
index 0000000000..6e1cb71d28
--- /dev/null
+++ b/server/src/__tests__/invite-url-public-base-url.test.ts
@@ -0,0 +1,174 @@
+/**
+ * TDD: authPublicBaseUrl takes precedence over request-derived host when building invite URLs.
+ * These tests are written first (will fail until the implementation lands).
+ */
+import express from "express";
+import request from "supertest";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+const logActivityMock = vi.fn();
+
+function registerModuleMocks() {
+ vi.doMock("../services/index.js", () => ({
+ accessService: () => ({
+ isInstanceAdmin: vi.fn(),
+ canUser: vi.fn(),
+ hasPermission: vi.fn(),
+ }),
+ agentService: () => ({
+ getById: vi.fn(),
+ }),
+ boardAuthService: () => ({
+ createChallenge: vi.fn(),
+ resolveBoardAccess: vi.fn(),
+ assertCurrentBoardKey: vi.fn(),
+ revokeBoardApiKey: vi.fn(),
+ }),
+ deduplicateAgentName: vi.fn(),
+ logActivity: (...args: unknown[]) => logActivityMock(...args),
+ notifyHireApproved: vi.fn(),
+ }));
+}
+
+function createDbStub() {
+ const createdInvite = {
+ id: "invite-1",
+ companyId: "company-1",
+ inviteType: "company_join",
+ allowedJoinTypes: "human",
+ tokenHash: "hash",
+ defaultsPayload: { humanRole: "viewer" },
+ expiresAt: new Date("2027-03-10T00:00:00.000Z"),
+ invitedByUserId: null,
+ revokedAt: null,
+ acceptedAt: null,
+ createdAt: new Date("2026-03-07T00:00:00.000Z"),
+ updatedAt: new Date("2026-03-07T00:00:00.000Z"),
+ };
+
+ return {
+ insert() {
+ return {
+ values() {
+ return {
+ returning() {
+ return Promise.resolve([createdInvite]);
+ },
+ };
+ },
+ };
+ },
+ select(_shape?: unknown) {
+ return {
+ from() {
+ const query = {
+ leftJoin() {
+ return query;
+ },
+ where() {
+ return Promise.resolve([{
+ name: "Acme Robotics",
+ brandColor: "#114488",
+ logoAssetId: null,
+ }]);
+ },
+ };
+ return query;
+ },
+ };
+ },
+ };
+}
+
+async function createApp(authPublicBaseUrl?: string) {
+ const [{ accessRoutes }, { errorHandler }] = await Promise.all([
+ import("../routes/access.js"),
+ import("../middleware/index.js"),
+ ]);
+ const app = express();
+ app.use(express.json());
+ app.use((req, _res, next) => {
+ (req as any).actor = {
+ type: "board",
+ source: "local_implicit",
+ userId: null,
+ companyIds: ["company-1"],
+ };
+ next();
+ });
+ app.use(
+ "/api",
+ accessRoutes(createDbStub() as any, {
+ deploymentMode: "local_trusted",
+ deploymentExposure: "private",
+ bindHost: "127.0.0.1",
+ allowedHostnames: [],
+ authPublicBaseUrl,
+ }),
+ );
+ app.use(errorHandler);
+ return app;
+}
+
+describe("invite URL: authPublicBaseUrl precedence", () => {
+ beforeEach(() => {
+ vi.resetModules();
+ vi.doUnmock("../services/index.js");
+ vi.doUnmock("../routes/access.js");
+ vi.doUnmock("../routes/authz.js");
+ vi.doUnmock("../middleware/index.js");
+ registerModuleMocks();
+ vi.clearAllMocks();
+ logActivityMock.mockReset();
+ });
+
+ it("uses authPublicBaseUrl for inviteUrl when configured, ignoring request host", async () => {
+ const app = await createApp(
+ "http://gus-pinsoneault-framework.tail302fee.ts.net:3100",
+ );
+
+ const res = await request(app)
+ .post("/api/companies/company-1/invites")
+ .set("host", "127.0.0.1:3100")
+ .set("x-forwarded-proto", "http")
+ .send({ allowedJoinTypes: "human", humanRole: "viewer" });
+
+ expect(res.status).toBe(201);
+ expect(res.body.inviteUrl).toMatch(
+ /^http:\/\/gus-pinsoneault-framework\.tail302fee\.ts\.net:3100\/invite\/pcp_invite_/,
+ );
+ expect(res.body.inviteUrl).not.toContain("127.0.0.1");
+ });
+
+ it("falls back to request-derived host when authPublicBaseUrl is not configured", async () => {
+ const app = await createApp(undefined);
+
+ const res = await request(app)
+ .post("/api/companies/company-1/invites")
+ .set("host", "paperclip.example")
+ .set("x-forwarded-proto", "https")
+ .send({ allowedJoinTypes: "human", humanRole: "viewer" });
+
+ expect(res.status).toBe(201);
+ expect(res.body.inviteUrl).toMatch(
+ /^https:\/\/paperclip\.example\/invite\/pcp_invite_/,
+ );
+ });
+
+ it("strips trailing slash from authPublicBaseUrl before joining with invite path", async () => {
+ const app = await createApp(
+ "http://gus-pinsoneault-framework.tail302fee.ts.net:3100/",
+ );
+
+ const res = await request(app)
+ .post("/api/companies/company-1/invites")
+ .set("host", "127.0.0.1:3100")
+ .send({ allowedJoinTypes: "human", humanRole: "viewer" });
+
+ expect(res.status).toBe(201);
+ expect(res.body.inviteUrl).not.toContain("//invite/");
+ expect(res.body.inviteUrl).toMatch(
+ /^http:\/\/gus-pinsoneault-framework\.tail302fee\.ts\.net:3100\/invite\/pcp_invite_/,
+ );
+ });
+});
diff --git a/server/src/app.ts b/server/src/app.ts
index 83ba9f791f..c641afd423 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -260,6 +260,7 @@ export async function createApp(
deploymentExposure: DeploymentExposure;
allowedHostnames: string[];
bindHost: string;
+ authPublicBaseUrl?: string;
authReady: boolean;
companyDeletionEnabled: boolean;
instanceId?: string;
@@ -568,6 +569,7 @@ export async function createApp(
deploymentExposure: opts.deploymentExposure,
bindHost: opts.bindHost,
allowedHostnames: opts.allowedHostnames,
+ authPublicBaseUrl: opts.authPublicBaseUrl,
}),
);
app.use("/api", api);
diff --git a/server/src/index.ts b/server/src/index.ts
index 5f3f129ffe..b46b9d2324 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -768,6 +768,7 @@ export async function startServer(): Promise<StartedServer> {
deploymentExposure: config.deploymentExposure,
allowedHostnames: config.allowedHostnames,
bindHost: config.host,
+ authPublicBaseUrl: config.authPublicBaseUrl,
authReady,
companyDeletionEnabled: config.companyDeletionEnabled,
pluginMigrationDb: pluginMigrationDb as any,
diff --git a/server/src/routes/access.ts b/server/src/routes/access.ts
index 39889d19b2..ea1ce6a183 100644
--- a/server/src/routes/access.ts
+++ b/server/src/routes/access.ts
@@ -141,6 +141,11 @@ function requestBaseUrl(req: Request) {
return `${proto}://${host}`;
}
+function resolveBaseUrl(req: Request, authPublicBaseUrl?: string): string {
+ if (authPublicBaseUrl) return authPublicBaseUrl.replace(/\/+$/, "");
+ return requestBaseUrl(req);
+}
+
function buildCliAuthApprovalPath(challengeId: string, token: string) {
return `/cli-auth/${challengeId}?token=${encodeURIComponent(token)}`;
}
@@ -1078,12 +1083,13 @@ function toInviteSummaryResponse(
brandColor: string | null;
logoUrl: string | null;
}
- | null = null
+ | null = null,
+ authPublicBaseUrl?: string
) {
const companyInfo = typeof company === "string"
? { name: company, brandColor: null, logoUrl: null }
: company;
- const baseUrl = requestBaseUrl(req);
+ const baseUrl = resolveBaseUrl(req, authPublicBaseUrl);
const invitePath = `/invite/${token}`;
const onboardingPath = `/api/invites/${token}/onboarding`;
const onboardingTextPath = `/api/invites/${token}/onboarding.txt`;
@@ -1698,9 +1704,10 @@ function buildInviteOnboardingManifest(
deploymentExposure: DeploymentExposure;
bindHost: string;
allowedHostnames: string[];
+ authPublicBaseUrl?: string;
}
) {
- const baseUrl = requestBaseUrl(req);
+ const baseUrl = resolveBaseUrl(req, opts.authPublicBaseUrl);
const skillPath = `/api/invites/${token}/skills/paperclip`;
const skillUrl = baseUrl ? `${baseUrl}${skillPath}` : skillPath;
const registrationEndpointPath = `/api/invites/${token}/accept`;
@@ -1729,7 +1736,8 @@ function buildInviteOnboardingManifest(
req,
token,
invite,
- opts.companyName ?? null
+ opts.companyName ?? null,
+ opts.authPublicBaseUrl
),
onboarding: {
instructions:
@@ -1796,6 +1804,7 @@ export function buildInviteOnboardingTextDocument(
deploymentExposure: DeploymentExposure;
bindHost: string;
allowedHostnames: string[];
+ authPublicBaseUrl?: string;
}
) {
const manifest = buildInviteOnboardingManifest(req, token, invite, opts);
@@ -2604,6 +2613,7 @@ export function accessRoutes(
allowedHostnames: string[];
inviteResolutionNetwork?: Partial<InviteResolutionNetwork>;
inviteRateLimiter?: InviteRateLimiter;
+ authPublicBaseUrl?: string;
}
) {
const router = Router();
@@ -3318,7 +3328,8 @@ export function accessRoutes(
req,
token,
created,
- companyBranding
+ companyBranding,
+ opts.authPublicBaseUrl
);
res.status(201).json({
...created,
@@ -3372,7 +3383,8 @@ export function accessRoutes(
req,
token,
created,
- companyBranding
+ companyBranding,
+ opts.authPublicBaseUrl
);
res.status(201).json({
...created,
@@ -3412,7 +3424,7 @@ export function accessRoutes(
)
: null;
res.json({
- ...toInviteSummaryResponse(req, token, invite, companyBranding),
+ ...toInviteSummaryResponse(req, token, invite, companyBranding, opts.authPublicBaseUrl),
invitedByUserName: inviterName,
joinRequestStatus: inviteJoinRequest?.status ?? null,
joinRequestType: inviteJoinRequest?.requestType ?? null,