TASK22224: harden setupcontainer hash compatibility parity

This commit is contained in:
2026-03-23 17:59:31 +00:00
parent 6e02ffe26d
commit 3f5006a744
2 changed files with 50 additions and 22 deletions
+25 -22
View File
@@ -1,10 +1,4 @@
import {
createContainer,
createContainerSas,
getContainers,
getBlobs,
uploadFile
} from "../../../actions/azurestorage";
import { createContainer } from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions/core/hash";
import { consoleLogger } from "../../../actions/core/logger";
import { respondError, respondSuccess } from "../middleware/apiResponse";
@@ -16,8 +10,8 @@ const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.ident;
var checkHash = req.query.hash;
const containerName = req.query.ident;
const checkHash = req.query.hash;
if (
typeof containerName === "undefined" ||
@@ -32,9 +26,19 @@ ApiProxy.get(async (req, res) => {
});
}
var checkquerypath = "/api/file/setupcontainer?ident=" + containerName;
const containerNameTrimmed = containerName.trim();
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
const hashCandidatePaths = [
"/api/file/setupcontainer?ident=" + containerNameTrimmed,
"/api/file/setupcontainer?ident=" +
encodeURIComponent(containerNameTrimmed)
];
const isHashValid = hashCandidatePaths.some(
(candidatePath) => hashAPIPath(candidatePath) == "&hash=" + checkHash
);
if (!isHashValid) {
return respondError(res, {
status: 400,
code: "INVALID_HASH",
@@ -42,18 +46,17 @@ ApiProxy.get(async (req, res) => {
});
}
await createContainer(containerName)
.then((data) => {
return respondSuccess(res, { data: "success", output: data });
})
.catch((error) => {
consoleLogger(error);
return respondError(res, {
status: 400,
code: "SETUP_CONTAINER_FAILED",
message: "Failed to setup container"
});
try {
const data = await createContainer(containerNameTrimmed);
return respondSuccess(res, { data: "success", output: data });
} catch (error) {
consoleLogger(error);
return respondError(res, {
status: 400,
code: "SETUP_CONTAINER_FAILED",
message: "Failed to setup container"
});
}
});
export const config = {