Skip to content

Fix github.com matching #167

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

Merged
merged 3 commits into from
Sep 9, 2024
Merged

Fix github.com matching #167

merged 3 commits into from
Sep 9, 2024

Conversation

yoannchaudet
Copy link
Contributor

This PR addresses https://github.com/github/pages-health-check/security/code-scanning/1.

It just does better URL handling by relaying on a regular expression.

@yoannchaudet yoannchaudet requested a review from a team September 9, 2024 20:42
@yoannchaudet yoannchaudet merged commit c0ac8fd into master Sep 9, 2024
6 checks passed
@yoannchaudet yoannchaudet deleted the github.com-matching branch September 9, 2024 21:04
Copy link
Contributor

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly drive-by comment. Hope all's well!

@@ -283,7 +283,7 @@ def pages_dot_github_dot_com?

# Is this domain owned by GitHub?
def github_domain?
!!host.downcase.end_with?("github.com")
!!host.match(/(\A|\.)github\.com\.?\z/i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a test, it's a bit difficult to know what potential problematic input this also handles. In general regular expressions are much slower in Ruby than string comparisons, but moreover they're a bit harder to audit/grok. I see it matches more cases like github.com. (trailing period) and enforces either strictly github.com or a subdomain thereof, but it's not necessarily clear what other cases you might want to include.

Checking host.downcase.eql?("github.com") || host.downcase.end_with?(".github.com") could be a more direct alternative if you're interested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Always nice to see you around!

Thanks for the feedback 🙇. Here goes: #172

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.

3 participants