Skip to content

feat: Add _redirects max rule count validation

Jaime Martinez requested to merge nfriend-limit-redirects-rule-count into master

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:

The _redirects file contains (1010) rules, more than the maximum of 1000 rules. Only the first 1000 rules will be processed.
1010 rules
rule 1: valid
rule 2: valid
rule 3: 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)

Original MR !552 (closed) by @nfriend 🙌

TODO

Merge request reports