Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export async function listInvitations(teamId: string) {
}));
}

export async function inviteUser(teamId: string, email: string, callbackUrl: string) {
export async function inviteUser(teamId: string, email: string, origin: string) {
const callbackUrl = new URL(stackServerApp.urls.teamInvitation, origin).toString();
const user = await stackServerApp.getUser();
const team = await user?.getTeam(teamId);
if (!team) {
Expand Down
30 changes: 30 additions & 0 deletions apps/e2e/tests/backend/endpoints/api/v1/team-invitations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,33 @@ it("errors with item_quantity_insufficient_amount when accepting invite without
}
`);
});

it("should error when untrusted callback URL is provided", async ({ expect }) => {
const { teamId } = await Team.create();
const receiveMailbox = createMailbox();

backendContext.set({ userAuth: null });
const sendTeamInvitationResponse = await niceBackendFetch("/api/v1/team-invitations/send-code", {
method: "POST",
accessType: "server",
body: {
email: receiveMailbox.emailAddress,
team_id: teamId,
callback_url: "https://malicious.com/callback",
},
});

expect(sendTeamInvitationResponse).toMatchInlineSnapshot(`
NiceResponse {
"status": 400,
"body": {
"code": "REDIRECT_URL_NOT_WHITELISTED",
"error": "Redirect URL not whitelisted. Did you forget to add this domain to the trusted domains list on the Stack Auth dashboard?",
},
"headers": Headers {
"x-stack-known-error": "REDIRECT_URL_NOT_WHITELISTED",
<some fields may have been hidden>,
},
}
`);
});