Skip to content

Commit

Permalink
fix: add validation on data.method when using tranport.request
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhoue-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Jun 30, 2023
1 parent c821a2a commit ca3a5da
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions server/services/CommonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from "../../../../src/core/server";
import { IAPICaller } from "../../models/interfaces";

const VALID_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE"];

export interface ICommonCaller {
<T>(arg: any): T;
}
Expand Down Expand Up @@ -42,6 +44,22 @@ export default class IndexService {
if (endpoint === "transport.request" && typeof finalData?.path === "string" && !/^\//.test(finalData?.path || "")) {
finalData.path = `/${finalData.path || ""}`;
}

/**
* Check valid method here
*/
if (endpoint === "transport.request" && data?.method) {
if (VALID_METHODS.indexOf(data.method?.toUpperCase()) === -1) {
return response.custom({
statusCode: 200,
body: {
ok: false,
error: `Method must be one of, case insensitive ['HEAD', 'GET', 'POST', 'PUT', 'DELETE']. Received '${data.method}'.`,
},
});
}
}

const payload = useQuery ? JSON.parse(finalData || "{}") : finalData;
const commonCallerResponse = await callWithRequest(endpoint, payload || {});
return response.custom({
Expand Down

0 comments on commit ca3a5da

Please sign in to comment.