@@ -3366,6 +3366,34 @@ func TestValidateNginxIngressAnnotations(t *testing.T) {
33663366 },
33673367 msg : "invalid nginx.org/rewrite-target annotation, path traversal with ..\\ (Windows style)" ,
33683368 },
3369+ {
3370+ annotations : map [string ]string {
3371+ "nginx.org/rewrite-target" : "/foo/$1; } path / { my/location/test/ }" ,
3372+ },
3373+ specServices : map [string ]bool {},
3374+ isPlus : false ,
3375+ appProtectEnabled : false ,
3376+ appProtectDosEnabled : false ,
3377+ internalRoutesEnabled : false ,
3378+ expectedErrors : []string {
3379+ `annotations.nginx.org/rewrite-target: Invalid value: "/foo/$1; } path / { my/location/test/ }": NGINX configuration syntax characters (;{}) and []|<>,^` + "`" + `~ not allowed in rewrite target` ,
3380+ },
3381+ msg : "invalid nginx.org/rewrite-target annotation, NGINX configuration syntax characters (;{}) not allowed in rewrite target" ,
3382+ },
3383+ {
3384+ annotations : map [string ]string {
3385+ "nginx.org/rewrite-target" : "/api\n path" ,
3386+ },
3387+ specServices : map [string ]bool {},
3388+ isPlus : false ,
3389+ appProtectEnabled : false ,
3390+ appProtectDosEnabled : false ,
3391+ internalRoutesEnabled : false ,
3392+ expectedErrors : []string {
3393+ `annotations.nginx.org/rewrite-target: Invalid value: "/api\npath": control characters not allowed in rewrite target` ,
3394+ },
3395+ msg : "invalid nginx.org/rewrite-target annotation, control characters not allowed in rewrite target" ,
3396+ },
33693397 {
33703398 annotations : map [string ]string {
33713399 "nginx.org/rewrite-target" : "api/users" ,
@@ -3380,6 +3408,34 @@ func TestValidateNginxIngressAnnotations(t *testing.T) {
33803408 },
33813409 msg : "invalid nginx.org/rewrite-target annotation, does not start with slash" ,
33823410 },
3411+ {
3412+ annotations : map [string ]string {
3413+ "nginx.org/rewrite-target" : "/api/v1`; proxy_pass http://evil.com; #" ,
3414+ },
3415+ specServices : map [string ]bool {},
3416+ isPlus : false ,
3417+ appProtectEnabled : false ,
3418+ appProtectDosEnabled : false ,
3419+ internalRoutesEnabled : false ,
3420+ expectedErrors : []string {
3421+ "annotations.nginx.org/rewrite-target: Invalid value: \" /api/v1`; proxy_pass http://evil.com; #\" : NGINX configuration syntax characters (;{}) and []|<>,^`~ not allowed in rewrite target" ,
3422+ },
3423+ msg : "invalid nginx.org/rewrite-target annotation, backtick and semicolon injection" ,
3424+ },
3425+ {
3426+ annotations : map [string ]string {
3427+ "nginx.org/rewrite-target" : "/path/$1|/backup/$1" ,
3428+ },
3429+ specServices : map [string ]bool {},
3430+ isPlus : false ,
3431+ appProtectEnabled : false ,
3432+ appProtectDosEnabled : false ,
3433+ internalRoutesEnabled : false ,
3434+ expectedErrors : []string {
3435+ "annotations.nginx.org/rewrite-target: Invalid value: \" /path/$1|/backup/$1\" : NGINX configuration syntax characters (;{}) and []|<>,^`~ not allowed in rewrite target" ,
3436+ },
3437+ msg : "invalid nginx.org/rewrite-target annotation, pipe character for alternatives" ,
3438+ },
33833439 }
33843440
33853441 for _ , test := range tests {
0 commit comments