Skip to content

Commit

Permalink
fix(core): add callback protocol validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Nov 11, 2023
1 parent c7bbeea commit ce4f57c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/api/src/graphql/public/types/scalar/endpoint-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const EndpointUrl = GT.Scalar({

function validUrlValue(value: string) {
try {
new URL(value)
const url = new URL(value)
if (url.protocol !== "https:" && url.protocol !== "http:") {
return new InputValidationError({ message: "Invalid value for EndpointUrl" })
}
return value
} catch (error) {
return new InputValidationError({ message: "Invalid value for EndpointUrl" })
Expand Down
3 changes: 3 additions & 0 deletions core/api/src/services/svix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ const handleCommonErrors = (err: Error | string | unknown) => {
const match = (knownErrDetail: RegExp): boolean => knownErrDetail.test(errMsg)

switch (true) {
case match(KnownSvixErrorMessages.InvalidUrlProtocol):
return new InvalidUrlError("URL must have a valid protocol")
case match(KnownSvixErrorMessages.InvalidHttpsUrl):
return new InvalidUrlError("URL must be https")

Expand All @@ -186,4 +188,5 @@ const handleCommonErrors = (err: Error | string | unknown) => {
}
export const KnownSvixErrorMessages = {
InvalidHttpsUrl: /endpoint_https_only/,
InvalidUrlProtocol: /must be http or https/,
} as const

0 comments on commit ce4f57c

Please sign in to comment.