Skip to content
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

Merged
merged 7 commits into from
Feb 10, 2025
Merged
12 changes: 12 additions & 0 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/

A [=/service worker=] has an associated <dfn>list of router rules</dfn> (a [=list=] of {{RouterRule}}s). It is initially an empty [=list=].

A [=/service worker=] has an associated <dfn>router rule count</dfn> (the number of registered {{RouterRule}}s). It is initially set to zero.
sisidovski marked this conversation as resolved.
Show resolved Hide resolved

Note: [=router rule count=] is defined as the limit of the total number of registered router rules. This prevents the user agent from spending much resources by evaluating too many router rules. The limit is 1024.

A [=/service worker=] is said to be <dfn>running</dfn> if its [=event loop=] is running.

<section>
Expand Down Expand Up @@ -1600,6 +1604,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
};
</pre>

Note: {{RouterCondition/_or}} and {{RouterCondition/not}} might have the other {{RouterCondition/_or}} or {{RouterCondition/not}} inside. To avoid spending much resources by the nested condition or performance penalty on evaluation, depth of such nested conditions can be limited.

<section>
<h4 id="register-router-method">{{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}}</h4>

Expand Down Expand Up @@ -3399,6 +3405,9 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
Note: For ease of understanding the router rule, the "or" condition is mutually exclusive with other conditions.

1. Let |orConditions| be |condition|["{{RouterCondition/_or}}"].

Note: To limit the resource usage and a condition evaluation time, |orConditions|'s [=list/size=] can be limited.

1. For each |orCondition| of |orConditions|:
1. If running the [=Verify Router Condition=] algorithm with |orCondition| and |serviceWorker| returns false, return false.
1. Set |hasCondition| to true.
Expand All @@ -3409,6 +3418,9 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/

1. If running the [=Verify Router Condition=] algorithm with |condition|["{{RouterCondition/not}}"] and |serviceWorker| returns false, return false.
1. Set |hasCondition| to true.
1. If |hasCondition| is true, then:
1. Increament |serviceWorker|'s [=service worker/router rule count=] by one.
sisidovski marked this conversation as resolved.
Show resolved Hide resolved
1. If |serviceWorker|'s [=service worker/router rule count=] exceeds 1024, which is the limit of registered router rules, return false.
1. Return |hasCondition|.
</section>

Expand Down