Skip to content
Open
Changes from 1 commit
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 @@ -3,12 +3,14 @@
import { errorFormAction } from "@/api/helpers/errors";
import { extractIdsFromPath, getPathFromHeaders } from "@/lib/server-utils";
import {
Auth0SessionUser,
FormActionResult,
PaymentMetadata,
TokenPrecision,
TransactionMetadata,
TransactionStatus,
} from "@/lib/types";
import { getSession } from "@auth0/nextjs-auth0";
import { createSignedFetcher } from "aws-sigv4-fetch";

export type GetAccumulativePaymentsDataReturnType = {
Expand Down Expand Up @@ -85,6 +87,31 @@ export const getAccumulativePaymentsData = async (
const path = getPathFromHeaders() || "";
const { Teams: teamId } = extractIdsFromPath(path, ["Teams"]);

const session = await getSession();
const user = session?.user as Auth0SessionUser["user"];

if (!user) {
return errorFormAction({
message: "User is not authenticated",
app_id: appId,
team_id: teamId,
logLevel: "error",
});
}

const isTeamMember = user?.hasura?.memberships?.some(
(membership) => membership.team?.id === teamId,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Verify app ownership before authorizing access

This authorization only validates membership for the route-derived teamId, but the data fetch is keyed only by appId. That means a user who is a member of Team A can invoke this server action from a Team A route while supplying an appId that belongs to Team B, and isTeamMember still passes before returning Team B’s payment/transaction data. Please enforce that the requested appId belongs to the authorized team (or query by both team and app) before calling the internal endpoint; the same issue is duplicated in getAccumulativeTransactionsData.

Useful? React with 👍 / 👎.


if (!isTeamMember) {
return errorFormAction({
message: "User is not a member of this team",
app_id: appId,
team_id: teamId,
logLevel: "error",
});
}

try {
if (!process.env.NEXT_SERVER_INTERNAL_PAYMENTS_ENDPOINT) {
return errorFormAction({
Expand Down Expand Up @@ -197,6 +224,31 @@ export const getAccumulativeTransactionsData = async (
const path = getPathFromHeaders() || "";
const { Teams: teamId } = extractIdsFromPath(path, ["Teams"]);

const session = await getSession();
const user = session?.user as Auth0SessionUser["user"];

if (!user) {
return errorFormAction({
message: "User is not authenticated",
app_id: appId,
team_id: teamId,
logLevel: "error",
});
}

const isTeamMember = user?.hasura?.memberships?.some(
(membership) => membership.team?.id === teamId,
);

if (!isTeamMember) {
return errorFormAction({
message: "User is not a member of this team",
app_id: appId,
team_id: teamId,
logLevel: "error",
});
}

try {
if (!process.env.NEXT_SERVER_INTERNAL_PAYMENTS_ENDPOINT) {
return errorFormAction({
Expand Down
Loading