Skip to content

Commit e4b91c4

Browse files
committed
check if uuid param is valid uuid before endpoint and alert filtering
1 parent 2a38282 commit e4b91c4

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

backend/src/api/get-endpoints/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Request, Response } from "express"
2+
import validator from "validator"
23
import { GetEndpointsService } from "services/get-endpoints"
34
import { GetEndpointParams } from "@common/types"
45
import ApiResponseHandler from "api-response-handler"
6+
import Error404NotFound from "errors/error-404-not-found"
57

68
export const getEndpointsHandler = async (
79
req: Request,
@@ -22,6 +24,9 @@ export const getEndpointHandler = async (
2224
): Promise<void> => {
2325
try {
2426
const { endpointId } = req.params
27+
if (!validator.isUUID(endpointId)) {
28+
throw new Error404NotFound("Endpoint does not exist.")
29+
}
2530
const endpoint = await GetEndpointsService.getEndpoint(endpointId)
2631
await ApiResponseHandler.success(res, endpoint)
2732
} catch (err) {
@@ -47,6 +52,9 @@ export const getUsageHandler = async (
4752
): Promise<void> => {
4853
try {
4954
const { endpointId } = req.params
55+
if (!validator.isUUID(endpointId)) {
56+
throw new Error404NotFound("Endpoint does not exist.")
57+
}
5058
const usageData = await GetEndpointsService.getUsage(endpointId)
5159
await ApiResponseHandler.success(res, usageData)
5260
} catch (err) {

backend/src/services/alert/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Not,
77
QueryRunner,
88
} from "typeorm"
9+
import validator from "validator"
910
import jsonMap from "json-source-map"
1011
import yaml from "js-yaml"
1112
import SourceMap from "js-yaml-source-map"
@@ -29,6 +30,7 @@ import {
2930
import Error409Conflict from "errors/error-409-conflict"
3031
import Error500InternalServer from "errors/error-500-internal-server"
3132
import { getPathTokens } from "@common/utils"
33+
import Error404NotFound from "errors/error-404-not-found"
3234

3335
export class AlertService {
3436
static async updateAlert(
@@ -91,13 +93,16 @@ export class AlertService {
9193
let paginationParams: FindManyOptions<Alert> = {}
9294
let orderParams: FindOptionsOrder<Alert> = {}
9395

94-
if (alertParams?.uuid) {
96+
if (alertParams?.uuid && validator.isUUID(alertParams?.uuid)) {
9597
whereConditions = {
9698
...whereConditions,
9799
uuid: alertParams.uuid,
98100
}
99101
}
100-
if (alertParams?.apiEndpointUuid) {
102+
if (
103+
alertParams?.apiEndpointUuid &&
104+
validator.isUUID(alertParams?.apiEndpointUuid)
105+
) {
101106
whereConditions = {
102107
...whereConditions,
103108
apiEndpointUuid: alertParams.apiEndpointUuid,
@@ -195,6 +200,9 @@ export class AlertService {
195200

196201
static async getAlert(alertId: string): Promise<AlertResponse> {
197202
const alertRepository = AppDataSource.getRepository(Alert)
203+
if (!validator.isUUID(alertId)) {
204+
throw new Error404NotFound("Alert not found.")
205+
}
198206
return await alertRepository.findOneBy({ uuid: alertId })
199207
}
200208

frontend/src/pages/endpoint/[endpointUUID]/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const Endpoint = ({
4242
export const getServerSideProps: GetServerSideProps = async context => {
4343
const initAlertParams = {
4444
uuid: (context.query.uuid as string) || null,
45-
apiEndpointUuid: context.query.endpointUUID as string,
45+
apiEndpointUuid: (context.query.endpointUUID as string) || null,
4646
riskScores: [],
4747
status: [Status.OPEN],
4848
alertTypes: [],

0 commit comments

Comments
 (0)