Skip to content

Commit 256ef3f

Browse files
committed
fix: add constant and comments for max URL length in proxy helpers
1 parent 804a884 commit 256ef3f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/proxy/routes/helper.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import * as db from '../../db';
33
/** Regex used to analyze un-proxied Git URLs */
44
const GIT_URL_REGEX = /(.+:\/\/)([^/]+)(\/.+\.git)(\/.+)*/;
55

6+
/** Used to reject URLs that are too long and may be part of a DoS involving regex. */
7+
const MAX_URL_LENGTH = 512;
8+
69
/** Type representing a breakdown of Git URL (un-proxied)*/
710
export type GitUrlBreakdown = { protocol: string; host: string; repoPath: string };
811

@@ -26,7 +29,8 @@ export type GitUrlBreakdown = { protocol: string; host: string; repoPath: string
2629
* @return {GitUrlBreakdown | null} A breakdown of the components of the URL.
2730
*/
2831
export const processGitUrl = (url: string): GitUrlBreakdown | null => {
29-
if (url.length > 512) {
32+
// limit URL length to avoid DoS via Regex issue detection in SAST scans
33+
if (url.length > MAX_URL_LENGTH) {
3034
console.error(`The git URL is too long: ${url}`);
3135
return null;
3236
}
@@ -69,7 +73,8 @@ export type UrlPathBreakdown = { repoPath: string; gitPath: string };
6973
* @return {GitUrlBreakdown | null} A breakdown of the components of the URL path.
7074
*/
7175
export const processUrlPath = (requestPath: string): UrlPathBreakdown | null => {
72-
if (requestPath.length > 512) {
76+
// limit URL length to avoid DoS via Regex issue detection in SAST scans
77+
if (requestPath.length > MAX_URL_LENGTH) {
7378
console.error(`The requestPath is too long: ${requestPath}`);
7479
return null;
7580
}
@@ -119,7 +124,8 @@ export type GitNameBreakdown = { project: string | null; repoName: string };
119124
* @return {GitNameBreakdown | null} A breakdown of the components of the URL.
120125
*/
121126
export const processGitURLForNameAndOrg = (gitUrl: string): GitNameBreakdown | null => {
122-
if (gitUrl.length > 512) {
127+
// limit URL length to avoid DoS via Regex issue detection in SAST scans
128+
if (gitUrl.length > MAX_URL_LENGTH) {
123129
console.error(`The git URL is too long: ${gitUrl}`);
124130
return null;
125131
}

0 commit comments

Comments
 (0)