Skip to content

feat: validate URL schemes in Anchor, IFrame and Page#open#24539

Draft
Artur- wants to merge 15 commits into
mainfrom
safe-url
Draft

feat: validate URL schemes in Anchor, IFrame and Page#open#24539
Artur- wants to merge 15 commits into
mainfrom
safe-url

Conversation

@Artur-

@Artur- Artur- commented Jun 8, 2026

Copy link
Copy Markdown
Member

Re-introduce URL-scheme validation for link and navigation sinks after the revert of #24371, using application-wide configuration plus a per-instance opt-out instead of the previous thread-unsafe static setter.

Safe schemes are read from the new com.vaadin.safeUrlSchemes (InitParameters.URL_SAFE_SCHEMES) configuration property, defaulting to http, https, mailto, tel and ftp so that script-capable schemes such as javascript and data are rejected. Setting the property to "*" marks every scheme as safe and keeps the previous behaviour. Relative URLs are always considered safe; the scheme is extracted manually rather than via URI parsing so that valid relative URLs (e.g. containing spaces) are not falsely rejected.

For trusted, hard-coded URLs whose scheme is not configured as safe, each sink offers an unsafe variant that bypasses validation: Anchor#setUnsafeHref, IFrame#setUnsafeSrc and Page#openUnsafe.

Artur- added 2 commits June 8, 2026 10:13
Re-introduce URL-scheme validation for link and navigation sinks after the
revert of #24371, using application-wide configuration plus a per-instance
opt-out instead of the previous thread-unsafe static setter.

Safe schemes are read from the new com.vaadin.safeUrlSchemes
(InitParameters.URL_SAFE_SCHEMES) configuration property, defaulting to http,
https, mailto, tel and ftp so that script-capable schemes such as javascript
and data are rejected. Setting the property to "*" marks every scheme as safe
and keeps the previous behaviour. Relative URLs are always considered safe; the
scheme is extracted manually rather than via URI parsing so that valid relative
URLs (e.g. containing spaces) are not falsely rejected.

For trusted, hard-coded URLs whose scheme is not configured as safe, each sink
offers an unsafe variant that bypasses validation: Anchor#setUnsafeHref,
IFrame#setUnsafeSrc and Page#openUnsafe.
@github-actions github-actions Bot added the +0.0.1 label Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Test Results

 1 438 files  ± 0   1 438 suites  ±0   1h 19m 32s ⏱️ - 3m 45s
10 142 tests +27  10 074 ✅ +27  68 💤 ±0  0 ❌ ±0 
10 614 runs  +27  10 545 ✅ +27  69 💤 ±0  0 ❌ ±0 

Results for commit 2b7d917. ± Comparison against base commit 1ac94ad.

♻️ This comment has been updated with latest results.

platosha and others added 9 commits June 9, 2026 13:05
…inService is available in UrlUtil.isSafeUrl(String) Javadoc
- Add `openUnsafe_twoArg_opensWithoutValidation` test case to verify that the second argument ("_blank") is correctly passed as a parameter without validation.
- Ensure that the underlying `executeJs` method still receives both parameters in the expected order.
- Verify that custom safe schemes are respected when configured via deployment properties.
- Ensure a wildcard scheme pattern ("*") allows any URL scheme, including unsafe ones like "javascript".
…guration

- Update javadoc in `UrlUtil.java` to explain that the wildcard entry `"*"` disables scheme validation even when mixed with other schemes.
- Update javadoc in `InitParameters.java` to reflect that any configuration entry equal to `"*"` acts as a global override for safe schemes.
…ponent constructors

- Assert that `Anchor` constructor throws `IllegalArgumentException` when provided with a URL using an unsafe scheme like "javascript", covering all constructor overloads including those with text and target arguments.
- Assert that the `IFrame` constructor throws `IllegalArgumentException` when initialized with a source URL containing an unsafe scheme.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 🔎Iteration reviews

Development

Successfully merging this pull request may close these issues.

3 participants