Skip to content

Potential fix for code scanning alert no. 21: Incomplete URL substring sanitization#4

Merged
Tanker187 merged 1 commit intomainfrom
alert-autofix-21
Feb 28, 2026
Merged

Potential fix for code scanning alert no. 21: Incomplete URL substring sanitization#4
Tanker187 merged 1 commit intomainfrom
alert-autofix-21

Conversation

@Tanker187
Copy link
Owner

Potential fix for https://github.com/Tanker187/stagehand/security/code-scanning/21

In general, to fix incomplete URL substring sanitization, you must parse the URL into its structured components and validate the host/hostname instead of searching for substrings in the full URL. Then compare the parsed host against an explicit whitelist or exact expected value, and perform any path/content checks separately on appropriate components.

Here, instead of url.includes("trivago.com"), we should parse url using the standard URL class and verify that hostname is exactly www.trivago.com (or one of a small, explicit set of allowed hostnames). We can keep the existing path fragment check (url.includes("hotel-h10-tribeca-madrid")) since that’s matching a specific hotel slug in the path, not a host. Concretely, right after obtaining const url = page.url();, introduce const parsedUrl = new URL(url); and then change the condition to:

const parsedUrl = new URL(url);

if (
  parsedUrl.hostname === "www.trivago.com" &&
  url.includes("hotel-h10-tribeca-madrid")
) {
  
}

This keeps existing functionality (we still check that we’re on trivago and on the right hotel page), but makes the host check precise and not vulnerable to arbitrary substrings. No extra imports are required because URL is available in modern Node/TypeScript environments; we also avoid modifying any other logic or returned values.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…g sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Tanker187 Tanker187 marked this pull request as ready for review February 28, 2026 03:42
@Tanker187 Tanker187 merged commit 3382ad9 into main Feb 28, 2026
18 of 25 checks passed
@Tanker187 Tanker187 self-assigned this Feb 28, 2026
Repository owner locked and limited conversation to collaborators Feb 28, 2026
@Tanker187 Tanker187 deleted the alert-autofix-21 branch February 28, 2026 03:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant