Skip to content

Commit 629a3ec

Browse files
committed
Check router rule recursion depth
1 parent 9f380a1 commit 629a3ec

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

docs/index.bs

+56-2
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,10 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
16061606

16071607
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.
16081608

1609+
A <dfn export id="dfn-count-router-condition-result">count router condition result</dfn> is a [=struct=] that consists of:
1610+
* A <dfn export id="dfn-count-router-condition-result-total-count" for="count router condition result">total count</dfn> (a number).
1611+
* A <dfn export id="dfn-dfn-count-router-condition-result-depth" for="count router condition result">depth</dfn> (a number).
1612+
16091613
<section>
16101614
<h4 id="register-router-method">{{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}}</h4>
16111615

@@ -1620,6 +1624,7 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
16201624
1. If running the [=Verify Router Condition=] algorithm with |rule|["{{RouterRule/condition}}"] and |serviceWorker| returns false, return [=a promise rejected with=] a {{TypeError}}.
16211625
1. Append |rule| to |routerRules|.
16221626
1. If |routerRules| [=list/contains=] a {{RouterRule}} whose {{RouterRule/source}} is either of "{{RouterSourceEnum/fetch-event}}" or "{{RouterSourceEnum/race-network-and-fetch-handler}}", and |serviceWorker|'s [=set of event types to handle=] does not [=set/contain=] {{ServiceWorkerGlobalScope/fetch!!event}}, return [=a promise rejected with=] a {{TypeError}}.
1627+
1. If running the [=Check Router Registration Limit=] with |serviceWorker| returns false, return [=a promise rejected with=] a {{TypeError}}.
16231628
1. Set |serviceWorker|'s [=service worker/list of router rules=] to |routerRules|.
16241629
1. Return [=a promise resolved with=] undefined.
16251630

@@ -3409,14 +3414,14 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
34093414
Note: To limit the resource usage and a condition evaluation time, |orConditions|'s [=list/size=] can be limited.
34103415

34113416
1. For each |orCondition| of |orConditions|:
3412-
1. If running the [=Verify Router Condition=] algorithm with |orCondition| and |serviceWorker| returns false, return false.
3417+
1. If running the [=Verify Router Condition=] algorithm with |orCondition| and |serviceWorker| and |registeredRuleCount| returns false, return false.
34133418
1. Set |hasCondition| to true.
34143419
1. If |condition|["{{RouterCondition/not}}"] [=map/exists=], then:
34153420
1. If |hasCondition| is true, return false.
34163421

34173422
Note: For ease of understanding the router rule, the "not" condition is mutually exclusive with other conditions.
34183423

3419-
1. If running the [=Verify Router Condition=] algorithm with |condition|["{{RouterCondition/not}}"] and |serviceWorker| returns false, return false.
3424+
1. If running the [=Verify Router Condition=] algorithm with |condition|["{{RouterCondition/not}}"] and |serviceWorker| and |registeredRuleCount| returns false, return false.
34203425
1. Set |hasCondition| to true.
34213426
1. If |hasCondition| is true, then:
34223427
1. Increament |serviceWorker|'s [=service worker/router rule count=] by one.
@@ -3468,6 +3473,55 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
34683473
1. Return true.
34693474
</section>
34703475

3476+
<section algorithm>
3477+
<h3 id="check-router-registration-limit"><dfn>Check Router Registration Limit</dfn></h3>
3478+
: Input
3479+
:: |serviceWorker|, a [=/service worker=]
3480+
: Output
3481+
:: a boolean
3482+
3483+
1. Let |currentResult| be a [=count router condition result=].
3484+
1. Set |currentResult|'s [=count router condition result/total count=] to 0.
3485+
1. Set |currentResult|'s [=count router condition result/depth=] to 1.
3486+
1. Let |maxRuleCount| be 1024.
3487+
1. Let |maxDepth| be 10.
3488+
1. [=list/For each=] |rule| of |serviceWorker|'s [=service worker/list of router rules=]:
3489+
1. Set |result| to be the result of running [=Count Router Inner Conditions=] with |rule|["{{RouterRule/condition}}"], |currentResult|, |maxRuleCount|, and |maxDepth|.
3490+
1. If |result|'s [=count router condition result/total count=] exceeds |maxRuleCount|, return false.
3491+
1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return false.
3492+
1. Set |currentResult|'s [=count router condition result/total count=] to |result|'s [=count router condition result/total count=].
3493+
1. return true.
3494+
</section>
3495+
3496+
<section algorithm>
3497+
<h3 id="count-router-inner-conditions"><dfn>Count Router Inner Conditions</dfn></h3>
3498+
: Input
3499+
:: |condition|, a {{RouterCondition}}
3500+
:: |result|, a [=count router condition result=]
3501+
:: |maxCount|, a number
3502+
:: |maxDepth|, a number
3503+
: Output
3504+
:: |result|, a [=count router condition result=]
3505+
3506+
1. Increment |result|'s [=count router condition result/total count=] by one.
3507+
1. If |result|'s [=count router condition result/total count=] exceeds |maxCount|, return |result|.
3508+
1. If |condition|["{{RouterCondition/_or}}"] [=map/exists=], then:
3509+
1. Increment |result|'s [=count router condition result/depth=] by one.
3510+
1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|.
3511+
1. For each |orCondition| of |condition|["{{RouterCondition/_or}}"]:
3512+
1. Set |result| to be the result of running [=Count Router Inner Conditions=] with |orCondition|, |result|, |maxCount|, and |maxDepth|.
3513+
1. If |result|'s [=count router condition result/total count=] exceeds |maxCount|, return |result|.
3514+
1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|.
3515+
1. Else if |condition|["{{RouterCondition/not}}"] [=map/exists=], then:
3516+
1. Increment |result|'s [=count router condition result/depth=] by one.
3517+
1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|.
3518+
1. Let |notCondition| be |condition|["{{RouterCondition/not}}"].
3519+
1. Let |result| be the result of running [=Count Router Inner Conditions=] with |condition|["{{RouterCondition/not}}"], |result|, |maxCount|, and |maxDepth|.
3520+
1. If |result|'s [=count router condition result/total count=] exceeds |maxCount|, return |result|.
3521+
1. If |result|'s [=count router condition result/depth=] exceeds |maxDepth|, return |result|.
3522+
1. Return |result|.
3523+
</section>
3524+
34713525
<section algorithm>
34723526
<h3 id="get-router-source-algorithm"><dfn>Get Router Source</dfn></h3>
34733527
: Input

0 commit comments

Comments
 (0)