Skip to content

Limit number of rules allowed in _redirects

What does this MR do?

Adds a new validation that limits the number rules allowed in _redirects to 1000.

When a _redirects file contains more than 1000 rules, the following error message is printed when the _redirects file is requested:

1001 rules
error: _redirects file may not contain more than 1000 rules
rule 1: valid
rule 2: valid
rule 3: valid
rule 4: valid
rule 5: valid
...

When a Pages site has more than 1000 rules, none of the rules are processed during normal requests.

Other details

We already validate that the _redirects file isn't too large: https://gitlab.com/gitlab-org/gitlab-pages/-/blob/96458b6f5841d8df17913a60dc7dbd266ac2100b/internal/redirects/redirects.go#L116.

Depending on the average length of the rules, this file size limit still allows a very large number of rules. (I was able to create a _redirects file with 10000 rules that was under the current 64kb limit.)

Context

This MR came out of a discussion here: !458 (comment 655200101)

Related to #500 (closed)

TODO

Edited by Jaime Martinez

Merge request reports