Skip to content

Potential fix for code scanning alert no. 44: Incomplete regular expression for hostnames#4111

Merged
tlimoncelli merged 1 commit intomainfrom
alert-autofix-44
Mar 2, 2026
Merged

Potential fix for code scanning alert no. 44: Incomplete regular expression for hostnames#4111
tlimoncelli merged 1 commit intomainfrom
alert-autofix-44

Conversation

@tlimoncelli
Copy link
Collaborator

Potential fix for https://github.com/StackExchange/dnscontrol/security/code-scanning/44

To fix the problem, all literal dots in the hostname portion of the regex must be escaped so they are treated as literal periods instead of “any character”. Since the base URL is held in selfLinkBasePath and then concatenated into the regex, the best approach is to escape the dots in selfLinkBasePath at construction time (while keeping / and : unescaped), so that the resulting full regex behaves as intended and still clearly expresses the expected URL prefix.

Concretely, in providers/gcloud/gcloudProvider.go, keep selfLinkBasePath as a normal string constant for use elsewhere, but when building networkURLCheck, wrap selfLinkBasePath with regexp.QuoteMeta. Then append the rest of the regex (project ID and network name parts) as before. regexp.QuoteMeta(selfLinkBasePath) will escape all regex metacharacters (including .), eliminating the over-permissive matching on the host, while preserving the intended matching of path structure and constraints on project/network names. No new imports are needed, since regexp is already imported. The only line to change is the definition of networkURLCheck.

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

…ession for hostnames

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@tlimoncelli tlimoncelli marked this pull request as ready for review March 2, 2026 17:07
@tlimoncelli tlimoncelli merged commit faa7e4f into main Mar 2, 2026
30 checks passed
@tlimoncelli tlimoncelli deleted the alert-autofix-44 branch March 2, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant