fix(security): enforce ownership on appeal and representation blob proxies

This commit is contained in:
2026-11-05 12:53:24 +00:00
parent 0a115a8808
commit 9d6d3b9f71
3 changed files with 238 additions and 24 deletions
@@ -4,16 +4,38 @@ import { consoleLogger } from "../../../actions/core/logger";
import { hashAPIPath } from "../../../actions/core/hash";
import axios from "axios";
import { respondError, respondSuccess } from "../middleware/apiResponse";
import { getServerSession } from "next-auth/next";
import { authOptions } from "../auth/[...nextauth]";
const BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
const hasValue = (value) =>
typeof value === "string" && value.trim().length > 0;
const forbidden = (res) =>
respondError(res, {
status: 403,
code: "FORBIDDEN",
message: "Request not permitted"
});
const isValidContainer = (value) =>
typeof value === "string" &&
value.length >= 3 &&
value.length <= 63 &&
/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(value);
export default async function ApiProxy(req, res) {
res.setHeader("Allow", "GET");
if (req.method !== "GET") {
return respondError(res, {
status: 405,
code: "METHOD_NOT_ALLOWED",
message: "Method not allowed"
});
}
const containerName = req.query.container;
if (!hasValue(containerName)) {
if (typeof containerName === "undefined" || containerName === "") {
return respondError(res, {
status: 400,
code: "MISSING_REQUIRED_QUERY",
@@ -21,10 +43,28 @@ export default async function ApiProxy(req, res) {
});
}
if (!isValidContainer(containerName)) {
return respondError(res, {
status: 400,
code: "INVALID_REQUEST",
message: "Invalid request"
});
}
const session = await getServerSession(req, res, authOptions(req, res));
if (
typeof session?.user?.id !== "string" ||
session.user.id.length === 0 ||
session.user.id !== containerName
) {
return forbidden(res);
}
const token = await getToken();
const queryUrl =
"/api/file/getawaitingsubmissionfromblob?container=" + containerName;
"/api/file/getawaitingsubmissionfromblob?container=" +
encodeURIComponent(containerName);
try {
const { data } = await axios.get(
+3 -2
View File
@@ -4,7 +4,8 @@ import { consoleLogger } from "../../../actions/core/logger";
import { hashAPIPath } from "../../../actions/core/hash";
import axios from "axios";
import { respondError, respondSuccess } from "../middleware/apiResponse";
import { getSession } from "next-auth/react";
import { getServerSession } from "next-auth/next";
import { authOptions } from "../auth/[...nextauth]";
const BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
@@ -50,7 +51,7 @@ export default async function ApiProxy(req, res) {
});
}
const session = await getSession({ req });
const session = await getServerSession(req, res, authOptions(req, res));
if (
typeof session?.user?.id !== "string" ||
session.user.id.length === 0 ||