Skip to content

Commit b05ac32

Browse files
sisidovskiyoshisatoyanagisawadomenic
authored
Add limits to the number of router rule registration (#1752)
Limitations are set to the following values: * max conditions: 1024 * max depth: 10 (Please see the PR description to understand how they are counted) TypeError on exceeding the limits. --------- Co-authored-by: Yoshisato Yanagisawa <[email protected]> Co-authored-by: Domenic Denicola <[email protected]>
1 parent b6ac20c commit b05ac32

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/index.bs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,10 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
16021602
};
16031603
</pre>
16041604

1605+
A <dfn id="dfn-count-router-condition-result">count router condition result</dfn> is a [=struct=] that consists of:
1606+
* A <dfn id="dfn-count-router-condition-result-condition-count" for="count router condition result">condition count</dfn> (a number).
1607+
* A <dfn id="dfn-dfn-count-router-condition-result-quota-exceeded" for="count router condition result">quota exceeded</dfn> (a boolean).
1608+
16051609
<section>
16061610
<h4 id="register-router-method">{{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}}</h4>
16071611

@@ -1629,6 +1633,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
16291633
1. For each |rule| of |rules|:
16301634
1. Append |rule| to |allRules|.
16311635

1636+
1. If running the [=Check Router Registration Limit=] with |allRules| returns false, reject |promise| with a {{TypeError}}.
16321637
1. Set |serviceWorker|'s [=service worker/list of router rules=] to |allRules|.
16331638
1. Let |serviceWorkerEventLoop| be the [=current global object=]'s [=event loop=].
16341639
1. [=Queue a task=] to run the following steps on |serviceWorkerEventLoop| using the [=DOM manipulation task source=]:
@@ -3473,6 +3478,51 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
34733478
1. Return true.
34743479
</section>
34753480

3481+
<section algorithm>
3482+
<h3 id="check-router-registration-limit"><dfn>Check Router Registration Limit</dfn></h3>
3483+
3484+
: Input
3485+
:: |routerRules|, a [=list of router rules=]
3486+
: Output
3487+
:: a boolean
3488+
3489+
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.
3490+
3491+
1. Let |result| be a [=count router condition result=].
3492+
1. Set |result|'s [=count router condition result/condition count=] to 1024.
3493+
1. Set |result|'s [=count router condition result/quota exceeded=] to false.
3494+
1. [=list/For each=] |rule| of |routerRules|:
3495+
1. Set |result| to be the result of running [=Count Router Inner Conditions=] with |rule|["{{RouterRule/condition}}"], |result|, and 10.
3496+
1. If |result|'s [=count router condition result/quota exceeded=] is true, return false.
3497+
1. Return true.
3498+
</section>
3499+
3500+
<section algorithm>
3501+
<h3 id="count-router-inner-conditions"><dfn>Count Router Inner Conditions</dfn></h3>
3502+
3503+
: Input
3504+
:: |condition|, a {{RouterCondition}}
3505+
:: |result|, a [=count router condition result=]
3506+
:: |depth|, a number
3507+
: Output
3508+
:: |result|, a [=count router condition result=]
3509+
3510+
1. Decrement |result|'s [=count router condition result/condition count=] by one.
3511+
1. If |result|'s [=count router condition result/condition count=] is zero, or |depth| is zero, then:
3512+
1. Set |result|'s [=count router condition result/quota exceeded=] to be true.
3513+
1. Return |result|.
3514+
1. If |condition|["{{RouterCondition/_or}}"] [=map/exists=], then:
3515+
1. Decrement |depth| by one.
3516+
1. For each |orCondition| of |condition|["{{RouterCondition/_or}}"]:
3517+
1. Set |result| to be the result of running [=Count Router Inner Conditions=] with |orCondition|, |result|, and |depth|.
3518+
1. If |result|'s [=count router condition result/quota exceeded=] is true, return |result|.
3519+
1. Else if |condition|["{{RouterCondition/not}}"] [=map/exists=], then:
3520+
1. Decrement |depth| by one.
3521+
1. Set |result| to be the result of running [=Count Router Inner Conditions=] with |condition|["{{RouterCondition/not}}"], |result|, and |depth|.
3522+
1. If |result|'s [=count router condition result/quota exceeded=] is true, return |result|.
3523+
1. Return |result|.
3524+
</section>
3525+
34763526
<section algorithm>
34773527
<h3 id="get-router-source-algorithm"><dfn>Get Router Source</dfn></h3>
34783528
: Input

0 commit comments

Comments
 (0)