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

Specify a maximal depth of backtracking for the pattern attribute on input elements #9469

Open
vinhill opened this issue Jun 29, 2023 · 7 comments
Labels
integration Better coordination across standards needed topic: forms

Comments

@vinhill
Copy link
Contributor

vinhill commented Jun 29, 2023

WebKit and Blink enforce a maximal depth of backtracking of 1,000,000 (see here for WebKit, here for Blink) when checking an input's value against a regular expression specified in #the-pattern-attribute. Gecko is discussing this in Bug 1837772. Without such a limit, a pattern like (\d+)* can hang a tab.

Such a backtracking limit could be included in the spec around the pattern attribute and it might be worth to discuss whether this limit should also be applied in other situations. There is already this wpt testing this behavior.

@annevk
Copy link
Member

annevk commented Jun 30, 2023

This is a limit that appears to be implemented in the regular expression engine. It doesn't seem specific to input elements. As such this would be TC39 territory I think. And if it's not defined there the test is probably invalid.

cc @mathiasbynens @syg

@vinhill
Copy link
Contributor Author

vinhill commented Jul 4, 2023

For Blink, the limit does not apply to JavaScript code, i.e. /(\d+)*$/.exec("0000011111111111111000z"). It does though apply in WebKit.

Only Blinks ScriptRegexp constructor applies the backtracking limit and seems to be used only for C++-side regexes.

@mathiasbynens
Copy link
Member

@schuay @pthier, given that, do we really need to apply kBacktrackLimit for ScriptRegexp?

@schuay
Copy link

schuay commented Jul 4, 2023

Yes IMO this still makes sense - for Blink's ScriptRegexp, the reasoning is described at crbug.com/966405 and https://bugs.chromium.org/p/chromium/issues/detail?id=89872#c26.

@annevk
Copy link
Member

annevk commented Jul 7, 2023

@Constellation do you think it would make sense to have the limit on regular expressions only for <input pattern>? (WebKit currently has it on regular expressions in general.) So you'd only prevent against a loop when there's no JavaScript involved.

@msaboff
Copy link

msaboff commented Sep 5, 2023

I think it makes sense for RegExp engines to put a cap on recursion for both Scripts and HTML. Otherwise, as we can see, it is easy to create a webpage that hangs.

@annevk
Copy link
Member

annevk commented Sep 6, 2023

Thanks! I filed tc39/ecma262#3166 so TC39 can figure out how they want to approach this. Unless they define a limit inline, we'll need some kind of host hook if we are to enforce a limit.

zcorpan added a commit to web-platform-tests/wpt that referenced this issue Sep 18, 2023
OrKoN pushed a commit to web-platform-tests/wpt that referenced this issue Sep 18, 2023
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Sep 28, 2023
…be tentative, a=testonly

Automatic update from web-platform-tests
HTML: infinite_backtracking.html should be tentative

There's no spec yet, see whatwg/html#9469

--

wpt-commits: 2f2a72d30ef5153c1bc6cbfe22449c2b3e8a4090
wpt-pr: 40898
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Sep 29, 2023
…be tentative, a=testonly

Automatic update from web-platform-tests
HTML: infinite_backtracking.html should be tentative

There's no spec yet, see whatwg/html#9469

--

wpt-commits: 2f2a72d30ef5153c1bc6cbfe22449c2b3e8a4090
wpt-pr: 40898

UltraBlame original commit: 871a2a733ec4d9e7705838554b960dfa4c86ad62
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Sep 29, 2023
…be tentative, a=testonly

Automatic update from web-platform-tests
HTML: infinite_backtracking.html should be tentative

There's no spec yet, see whatwg/html#9469

--

wpt-commits: 2f2a72d30ef5153c1bc6cbfe22449c2b3e8a4090
wpt-pr: 40898

UltraBlame original commit: 871a2a733ec4d9e7705838554b960dfa4c86ad62
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this issue Sep 30, 2023
…be tentative, a=testonly

Automatic update from web-platform-tests
HTML: infinite_backtracking.html should be tentative

There's no spec yet, see whatwg/html#9469

--

wpt-commits: 2f2a72d30ef5153c1bc6cbfe22449c2b3e8a4090
wpt-pr: 40898
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Sep 30, 2023
…be tentative, a=testonly

Automatic update from web-platform-tests
HTML: infinite_backtracking.html should be tentative

There's no spec yet, see whatwg/html#9469

--

wpt-commits: 2f2a72d30ef5153c1bc6cbfe22449c2b3e8a4090
wpt-pr: 40898

UltraBlame original commit: 871a2a733ec4d9e7705838554b960dfa4c86ad62
Lightning00Blade pushed a commit to Lightning00Blade/wpt that referenced this issue Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration Better coordination across standards needed topic: forms
Development

No branches or pull requests

6 participants