@@ -13,6 +13,8 @@ import { QueuesUpdateCronBody } from "../types/queues/update-cron";
13
13
import { isValidCronExpression } from "../../../shared/is-valid-cron" ;
14
14
import { isValidTimezone } from "../../../shared/repeat" ;
15
15
16
+ import * as Url from "url"
17
+
16
18
const jobs : FastifyPluginCallback = ( fastify , opts , done ) => {
17
19
const jobsRepo = fastify . jobs ;
18
20
const queueRepo = jobsRepo . queueRepo ;
@@ -35,6 +37,11 @@ const jobs: FastifyPluginCallback = (fastify, opts, done) => {
35
37
return true ;
36
38
}
37
39
40
+ function isAbsoluteURL ( string : string ) : boolean {
41
+ const url = Url . parse ( string ) ;
42
+ return Boolean ( url . protocol && url . hostname ) ;
43
+ }
44
+
38
45
const baseSchema = {
39
46
tags : [ "Queueing" ] ,
40
47
security : fastify . adminBasedAuthEnabled
@@ -54,6 +61,12 @@ const jobs: FastifyPluginCallback = (fastify, opts, done) => {
54
61
"body.repeat.cron uses unsupported syntax. See https://github.com/harrisiirak/cron-parser for reference." ,
55
62
} ;
56
63
64
+ const INVALID_ENDPOINT_ERROR = {
65
+ statusCode : 400 ,
66
+ error : "Bad Request" ,
67
+ message : "endpoint needs to be absolute URL." ,
68
+ } ;
69
+
57
70
const INVALID_TIMEZONE_ERROR = {
58
71
statusCode : 400 ,
59
72
error : "Bad Request" ,
@@ -77,6 +90,10 @@ const jobs: FastifyPluginCallback = (fastify, opts, done) => {
77
90
const { tokenId, body } = request ;
78
91
const { endpoint } = request . params ;
79
92
93
+ if ( ! isAbsoluteURL ( endpoint ) ) {
94
+ return reply . status ( 400 ) . send ( INVALID_ENDPOINT_ERROR ) ;
95
+ }
96
+
80
97
if ( ! hasValidCronExpression ( body ) ) {
81
98
return reply . status ( 400 ) . send ( INVALID_CRON_EXPRESSION_ERROR ) ;
82
99
}
@@ -127,6 +144,10 @@ const jobs: FastifyPluginCallback = (fastify, opts, done) => {
127
144
) ;
128
145
}
129
146
147
+ if ( ! isAbsoluteURL ( endpoint ) ) {
148
+ return reply . status ( 400 ) . send ( INVALID_ENDPOINT_ERROR ) ;
149
+ }
150
+
130
151
if ( ! body . every ( hasValidCronExpression ) ) {
131
152
return reply . status ( 400 ) . send ( INVALID_CRON_EXPRESSION_ERROR ) ;
132
153
}
0 commit comments