Re: [w3c/ServiceWorker] Add limits to the number of router rule registration (PR #1752)

@yoshisatoyanagisawa commented on this pull request.



> @@ -3456,6 +3461,57 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
           1. Return true.
   </section>
 
+  <section algorithm>
+    <h3 id="check-router-registration-limit"><dfn>Check Router Registration Limit</dfn></h3>
+
+      : Input
+      :: |routerRules|, a [=list of router rules=]
+      : Output
+      :: a boolean
+
+      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.
+      1. Set |result|'s [=count router condition result/depth=] to 1.
+      1. Let |maxCount| be 1024.

Upon the sync, I think we agreed to:
1. do the "early return" by checking conditions and width,
2. and avoid checking the value twice by making count-router-inner-conditions to return an error in addition.  check-router-registration-limit just checks the error is set or not, and it won't check the number.

Stepping back, we do want to know the number of conditions but we do not need to know the depth.  Can we move |depth| to the argument of count-router-inner-conditions instead of the struct?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/pull/1752#discussion_r1938830140
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/pull/1752/review/2588993078@github.com>

Received on Monday, 3 February 2025 06:16:01 UTC