Skip to content

Fix out-of-bounds read for truncated percent-escape in opaque host - #37203

Open
shaggyinsomniac wants to merge 1 commit into
spring-projects:mainfrom
shaggyinsomniac:whatwg-opaque-host-oob
Open

Fix out-of-bounds read for truncated percent-escape in opaque host#37203
shaggyinsomniac wants to merge 1 commit into
spring-projects:mainfrom
shaggyinsomniac:whatwg-opaque-host-oob

Conversation

@shaggyinsomniac

Copy link
Copy Markdown

Fixes #37201

Description

The opaque-host percent-escape validation guard reads input.codePointAt(i + 2) after only checking input.length() - i < 2, so an input such as foo://%4 throws StringIndexOutOfBoundsException instead of reporting a validation error.

The guard now requires two code points after % and checks ASCII hex digits rather than ASCII digits, matching the URL spec and the existing code comment: invalid percent-escapes in opaque hosts are validation errors, not failures — the host %4 is accepted.

Test coverage

  • parseOpaqueHostTruncatedPercentEscape() — parses foo://%4 / foo://%4x with validation enabled, asserts the resulting host and that validation errors were reported
  • Fails on main with StringIndexOutOfBoundsException and passes with this change; the full :spring-web:test suite (3,919 tests) passes

@bclozel

bclozel commented Aug 27, 2026

Copy link
Copy Markdown
Member

Please sign the DCO.

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Aug 27, 2026
The opaque-host percent-escape validation guard reads
input.codePointAt(i + 2) after only checking 'input.length() - i < 2',
so an input such as 'foo://%4' throws StringIndexOutOfBoundsException
instead of reporting a validation error.

Fix the bounds guard to require two code points after '%' and check
ASCII hex digits rather than ASCII digits, matching the URL spec, where
invalid percent-escapes in opaque hosts are validation errors, not
failures.

Signed-off-by: Sagar Chanchal <Sagarr2112@gmail.com>
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WhatWgUrlParser throws StringIndexOutOfBoundsException for truncated percent-escape in opaque host

3 participants