-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add limits to the number of router rule registration #1752
base: main
Are you sure you want to change the base?
Conversation
b0af1d0
to
f427b1a
Compare
Note: Router conditions can be complex and nested using {{RouterCondition/_or}} and {{RouterCondition/not}}. To prevent excessive processing, this algorithm introduces two limits. First, the total number of conditions, counting all nested conditions, cannot exceed 1024. Second, the nesting depth is limited to 10 levels to avoid exponential computation. | ||
|
||
1. Let |result| be a [=count router condition result=]. | ||
1. Set |result|'s [=count router condition result/total count=] to 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the intention to set "total count" to 0 here instead of 1, and omit increment one in count-router-inner-conditions?
1. Let |result| be a [=count router condition result=]. | ||
1. Set |result|'s [=count router condition result/total count=] to 0. | ||
1. Set |result|'s [=count router condition result/depth=] to 1. | ||
1. Let |maxCount| be 1024. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess setting |maxCount| is to use the same value not only in check-router-registration-limit, but also in count-router-inner-conditions.
However, do we need to ask the browser implementor to implement the early return?
1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|. | ||
1. If |condition|["{{RouterCondition/_or}}"] [=map/exists=], then: | ||
1. Increment |result|'s [=count router condition result/depth=] by one. | ||
1. For each |orCondition| of |condition|["{{RouterCondition/_or}}"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that the number of conditions under |orCondition| may not be counted?
e.g.
or: [{singleRule}, {singleRule}, {singleRule}]
|result| might be overwritten by the result for {singleRule} for three times, but we want |result|'s [=total count=] to be three.
In #1746, we discussed if the spec should give guidelines about the limit of added routes, and how the user agent should behave if the added routes exceeds the limit.
We have an agreement that we're willing to pick some specific limits. This PR proposes 1024 as the total number of router conditions, and 10 as the max depth of router condition nesting level. If it exceeds those limits, the user agent throws a TypeError.
For the counting conditions part, let me clarify how we calculate the total count as this a bit tricky.
Assuming that router conditions can be nested by using
or
andnot
syntaxes. We count every sub router conditions inside the parentor
ornot
condition, including the parent condition itself.Here are some examples.
#1714 will be migrated into this PR.
Preview | Diff