Skip to content
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

fix(vendor): Remove excessive URL validation #1024

Merged
merged 3 commits into from
Feb 5, 2025
Merged

Conversation

mss
Copy link
Contributor

@mss mss commented Feb 5, 2025

what

  • Removed some excessive URL validation introduced in v1.130.0 which blocked valid URLs in vendor manifests.

why

  • The validation blocked shallow Git clones via depth while also specifying a ref (and other features supported by go-getter).
  • The check was completely removed because it is unnecessary in this context. It would probably help to avoid XSS in a web app and with untrusted input but that's not the environment Atmos is working in.
  • Completely broken URLs are already checked somewhere else (and by go-getter itself) so no call to url.Parse was added.

references

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced clarity of error messages related to URI validation, providing more context for debugging when invalid URIs are detected.
    • Simplified URI validation by removing checks for specific invalid characters, streamlining the overall validation process.

@mss mss requested a review from a team as a code owner February 5, 2025 10:55
@mergify mergify bot added the triage Needs triage label Feb 5, 2025
Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

📝 Walkthrough

Walkthrough

The update modifies the ValidateURI function in the getter utilities by removing the validation check for invalid characters in the URI. The changes specifically eliminate checks for characters such as <, >, |, &, ;, and $. Other validation checks, including those for empty URIs, maximum length, path traversal sequences, spaces, and scheme-specific formats, remain intact. Additionally, error handling in the ExecuteAtmosVendorInternal function has been improved to provide clearer error messages related to invalid URIs.

Changes

File(s) Change Summary
internal/exec/go_getter_utils.go Removed validation checks for invalid characters in the ValidateURI function.
internal/exec/vendor_utils.go Enhanced error messages in ExecuteAtmosVendorInternal for clarity regarding invalid URIs.

Assessment against linked issues

Objective (from issue [#1019]) Addressed Explanation
Prevent vendoring errors caused by invalid URI characters The removal of character validation may still allow problematic URIs.

Suggested labels

patch, minor

Suggested reviewers

  • osterman
  • aknysh

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc3da5a and 04be802.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/vendor_utils.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/exec/go_getter_utils.go (1)

34-36: Consider removing space validation.

Since go-getter handles URL validation and we're operating in a trusted environment, this check might be redundant.

-	if strings.Contains(uri, " ") {
-		return fmt.Errorf("URI cannot contain spaces: %v", uri)
-	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 300ca0f and ec6e3fe.

📒 Files selected for processing (1)
  • internal/exec/go_getter_utils.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
internal/exec/go_getter_utils.go (1)

38-47: Verify if scheme validation is necessary.

The scheme validation might be redundant since go-getter already validates URLs. However, if you decide to keep it, consider updating the valid schemes to match go-getter's supported schemes (documented in lines 193-241).

Let's check if go-getter performs scheme validation:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for scheme validation in go-getter
rg -A 5 'scheme|protocol' $(fd -t f -e go . | grep go-getter)

Length of output: 39042


Scheme validation is custom and not entirely redundant—but the valid schemes list needs review
Our investigation confirms that the code in internal/exec/go_getter_utils.go performs its own scheme validation (via the IsValidScheme function) rather than relying solely on go-getter’s internal URL checks. This extra validation catches unsupported schemes early with explicit error messages. However, the current validation only accepts "http", "https", "git", and "ssh", while the documentation (and go-getter’s own supported schemes) include additional protocols (e.g., file, dir, tar, zip, etc.). Consider updating the valid schemes list if you decide to keep this extra layer of validation.

internal/exec/go_getter_utils.go Outdated Show resolved Hide resolved
internal/exec/go_getter_utils.go Outdated Show resolved Hide resolved
Copy link
Member

@osterman osterman left a comment

Choose a reason for hiding this comment

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

Unless we introduce a function to mask URLs, we should not emit them in the error messages as they will leak basic auth credentials. For GitHub URLs we automatically inject tokens so we can pull from private repos and avoid rate limits.

@mss
Copy link
Contributor Author

mss commented Feb 5, 2025

Unless we introduce a function to mask URLs, we should not emit them in the error messages as they will leak basic auth credentials. For GitHub URLs we automatically inject tokens so we can pull from private repos and avoid rate limits.

Good point, I will remove that again. It would be helpful if the component was added to the output then but I don't know how to fix that quickly.

@mss
Copy link
Contributor Author

mss commented Feb 5, 2025

Unless we introduce a function to mask URLs, we should not emit them in the error messages as they will leak basic auth credentials. For GitHub URLs we automatically inject tokens so we can pull from private repos and avoid rate limits.

Good point, I will remove that again. It would be helpful if the component was added to the output then but I don't know how to fix that quickly.

Ok, I found a quick way to add that.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b0c673 and dc3da5a.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
internal/exec/vendor_utils.go (1)

373-374: LGTM: Improved error message for path traversal.

The simplified error message for path traversal cases is clearer and more focused.

internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
@osterman
Copy link
Member

osterman commented Feb 5, 2025

It would be helpful if the component was added to the output then but I don't know how to fix that quickly.

I’m on mobile, so I can’t easily verify. Since we return an error, it will propagate up the call stack to a point where we also have access to the component name. At that level, we can log it with structured key-value pairs. We’ve also introduced a global log instance with contextual support, making it easier to capture and enrich logs with relevant metadata.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 5, 2025
@mergify mergify bot removed the triage Needs triage label Feb 5, 2025
@mergify mergify bot removed the triage Needs triage label Feb 5, 2025
@osterman osterman added the patch A minor, backward compatible change label Feb 5, 2025
Copy link
Member

@osterman osterman left a comment

Choose a reason for hiding this comment

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

LGTM

@aknysh aknysh merged commit c76d05a into cloudposse:main Feb 5, 2025
45 checks passed
Copy link

github-actions bot commented Feb 5, 2025

These changes were released in v1.160.1.

Cerebrovinny pushed a commit that referenced this pull request Feb 9, 2025
* fix(vendor): Remove excessive URL validation

Fixes #1019

* feat(vendor): Add component to error message

---------

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vendoring: "URI contains invalid characters"
3 participants