@@ -3,6 +3,9 @@ import * as db from '../../db';
33/** Regex used to analyze un-proxied Git URLs */
44const GIT_URL_REGEX = / ( .+ : \/ \/ ) ( [ ^ / ] + ) ( \/ .+ \. g i t ) ( \/ .+ ) * / ;
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)*/
710export 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 */
2831export 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 */
7175export 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 */
121126export 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