mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-03-30 19:05:39 +00:00
Use json reviver in express.json() middleware. (#913)
This commit is contained in:
16
src/utils.ts
16
src/utils.ts
@@ -515,10 +515,18 @@ function patchMatrixClientForRetry() {
|
||||
let isMatrixClientPatchedForPrototypePollution = false;
|
||||
|
||||
export function jsonReviver<T = unknown>(key: string, value: T): T | undefined {
|
||||
if (key === "__proto__" || key === "constructor") {
|
||||
return undefined;
|
||||
} else {
|
||||
return value;
|
||||
switch (key) {
|
||||
case "__proto__":
|
||||
case "constructor":
|
||||
case "prototype":
|
||||
case "toString":
|
||||
case "valueOf":
|
||||
case "hasOwnProperty":
|
||||
case "__defineGetter__":
|
||||
case "__defineSetter__":
|
||||
return undefined;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
} from "@the-draupnir-project/matrix-basic-types";
|
||||
import { Logger, Task } from "matrix-protection-suite";
|
||||
import { SynapseHttpAntispam } from "./SynapseHTTPAntispam/SynapseHttpAntispam";
|
||||
import { jsonReviver } from "../utils";
|
||||
|
||||
const log = new Logger("WebAPIs");
|
||||
|
||||
@@ -41,7 +42,7 @@ export class WebAPIs {
|
||||
private readonly synapseHTTPAntispam: SynapseHttpAntispam | undefined
|
||||
) {
|
||||
// Setup JSON parsing.
|
||||
this.webController.use(express.json());
|
||||
this.webController.use(express.json({ reviver: jsonReviver }));
|
||||
this.synapseHTTPAntispam?.register(this.webController);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user