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 bug atmos vendor pull URI cannot contain path traversal sequences and git schema #899

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Dec 28, 2024

fix vendor bugs and add test for vendor

  • Fix git::http
  • Fix traverse path in vendor URL
  • Fix Support file://
  • add test cases for vendor

references

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for IP address information retrieval using IPinfo API.
    • Introduced new Terraform module for fetching IP metadata.
    • Enhanced configuration management for Terraform components and stacks.
  • Improvements

    • Enhanced URI handling and validation for the vendoring process.
    • Refined temporary directory naming for package installation.
    • Improved error handling for URI processing.
  • Testing

    • Added new test cases for CLI commands.
    • Expanded test coverage for vendor pull operations.
  • Documentation

    • Added README for new Terraform module.
    • Updated configuration examples and documentation.

@haitham911 haitham911 requested a review from a team as a code owner December 28, 2024 13:11
@mergify mergify bot added the triage Needs triage label Dec 28, 2024
Copy link
Contributor

coderabbitai bot commented Dec 28, 2024

📝 Walkthrough

Walkthrough

The pull request introduces comprehensive improvements to URI handling and validation in the Atmos vendoring system. The changes focus on enhancing the robustness of URI processing, particularly for local file paths, OCI schemes, and GitHub repositories. Key modifications include adding URL parsing capabilities, improving path normalization, and refining error handling across multiple utility functions in the vendoring process.

Changes

File Change Summary
internal/exec/vendor_utils.go Added URL parsing, improved URI validation logic, enhanced error messaging, and path normalization.
internal/exec/vendor_model.go Simplified temporary directory naming.
internal/exec/vendor_component_utils.go Enhanced URI handling with file scheme support.
examples/tests/test-vendor/atmos.yaml Added structured configuration for Terraform components and stacks.
examples/tests/test-vendor/test-components/README.md Added documentation for a Terraform module interacting with IPinfo API.
examples/tests/test-vendor/test-components/main.tf Introduced a new HTTP data block for IPinfo API requests.
examples/tests/test-vendor/test-components/outputs.tf Added output variable for metadata from IPinfo API.
examples/tests/test-vendor/test-components/providers.tf Added HTTP provider block for managing HTTP resources.
examples/tests/test-vendor/test-components/variables.tf Introduced a variable for optional IP address input.
examples/tests/test-vendor/test-components/versions.tf Specified required Terraform version.
examples/tests/test-vendor/vendor.yaml Introduced new configuration for managing vendor dependencies.
tests/fixtures/scenarios/complete/vendor.yaml Updated component sources and added new component.
tests/test-cases/demo-stacks.yaml Added new test cases for atmos CLI commands.

Assessment against linked issues

Objective Addressed Explanation
Support Path Traversals [#888, DEV-2891]
Fix git::http:// URL support [DEV-2892]
Support file:// paths [DEV-1896]

Possibly related PRs

  • package manager for vendor pull #768: This PR enhances the vendor pull functionality, which is directly related to the changes in the main PR that improve URI handling and validation in the vendor_utils.go file.
  • Fix vendor pull directory creation issue #782: This PR addresses a directory creation issue in the vendor pull command, which is relevant to the changes made in the main PR regarding the handling of URIs and paths.
  • fix vendor pull error message #940: This PR improves error messaging for the vendor pull command, which aligns with the main PR's focus on enhancing error handling for invalid URIs.

Suggested labels

minor

Suggested reviewers

  • osterman
  • aknysh
  • Gowiem
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 28, 2024
@mergify mergify bot removed the triage Needs triage label Dec 28, 2024
@mergify mergify bot added the triage Needs triage label Dec 28, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 28, 2024
@mergify mergify bot removed the triage Needs triage label Dec 28, 2024
@osterman
Copy link
Member

Please add test conditions or at least examples to examples/tests so we verify this works and don't introduce future regressions

@osterman osterman changed the title Issues 888 fix bug atmos vendor pull URI cannot contain path traversal sequences and git schema Dec 28, 2024
@aknysh
Copy link
Member

aknysh commented Dec 28, 2024

Please add test conditions or at least examples to examples/tests so we verify this works and don't introduce future regressions

the tests for many vendoring scenarios, including imports, are here https://github.com/cloudposse/atmos/blob/main/examples/tests/vendor.yaml
https://github.com/cloudposse/atmos/tree/main/examples/tests/vendor

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: 0

🧹 Nitpick comments (1)
examples/demo-vendoring/vendor.yaml (1)

12-12: Consider standardizing URL format across all components

While the new format with git::https:// is more secure, we should maintain consistency. The weather and ipinfo components still use the old format.

Consider updating all components to use the new format:

  - component: "weather"
-     source: "github.com/cloudposse/atmos.git//examples/demo-library/{{ .Component }}?ref={{.Version}}"
+     source: "git::https://github.com/cloudposse/atmos.git//examples/demo-library/{{ .Component }}?ref={{.Version}}"

  - component: "ipinfo"
-     source: "github.com/cloudposse/atmos.git//examples/demo-library/{{ .Component }}?ref={{.Version}}"
+     source: "git::https://github.com/cloudposse/atmos.git//examples/demo-library/{{ .Component }}?ref={{.Version}}"

Also applies to: 23-24, 31-32

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dcd0086 and ee879d9.

📒 Files selected for processing (1)
  • examples/demo-vendoring/vendor.yaml (1 hunks)
🔇 Additional comments (1)
examples/demo-vendoring/vendor.yaml (1)

12-12: APPROVED: Enhanced security with explicit Git protocol and HTTPS! 🛡️

The addition of git:: prefix and explicit HTTPS protocol improves security and clarity. Let's verify this new format works as expected.

✅ Verification successful

Let me check the validation code to understand how the URI is validated.


Let me check the actual implementation of the vendor utility functions.


Let me check the vendoring documentation for any additional context.


The new Git URL format is valid and secure! 🛡️

Based on the code analysis, the git::https:// format is fully supported by the validation logic in validateURI() function. The function specifically checks for valid schemes including git, and the URL format matches the expected pattern. The change improves security by making the protocol explicit while maintaining compatibility with the vendoring system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new Git URL format in other vendor configurations
# Look for any existing usage of the new format to confirm it's supported

# Search for similar Git URL patterns in vendor configs
echo "Searching for existing Git URL patterns in vendor configs..."
rg -g '*.yaml' -g '*.yml' 'git::https://' 

# Look for any validation-related code that might affect this URL format
echo "Checking for URL validation code..."
rg -t go 'validateURI|validateURL|validateGitURL'

Length of output: 581


Script:

#!/bin/bash
# Check the URI validation implementation
echo "Checking URI validation implementation..."
ast-grep --pattern 'func validateURI($_) {
  $$$
}'

# Look for any tests related to URI validation
echo "Checking for URI validation tests..."
rg -t go 'TestValidateURI|TestVendorURI'

# Check for any vendor-related test files
echo "Looking for vendor test files..."
fd -e go -e yaml test.*vendor

Length of output: 381


Script:

#!/bin/bash
# Get the content of vendor_utils.go
echo "Checking vendor utils implementation..."
cat internal/exec/vendor_utils.go

# Look for any vendor-related configuration or documentation
echo "Checking for vendor documentation..."
fd -e md -e txt vendor

Length of output: 21139


Script:

#!/bin/bash
# Check vendoring documentation
echo "Checking vendoring documentation..."
cat website/docs/glossary/vendoring.md

# Look for any test files with vendor examples
echo "Looking for vendor test examples..."
fd -e yaml -e yml test.*vendor

Length of output: 454

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2024
@mergify mergify bot removed the triage Needs triage label Dec 29, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2024
@mergify mergify bot removed the triage Needs triage label Dec 29, 2024
@mergify mergify bot added the triage Needs triage label Dec 29, 2024
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

🧹 Nitpick comments (1)
examples/tests/vendor.yaml (1)

Line range hint 16-24: Well-documented source configuration provides clear guidance 📘

The comprehensive documentation of supported protocols and URL formats serves as both a test case and implementation guide. This is particularly valuable for validating the URI validation changes.

Consider adding an explicit example of what path traversal sequences are not allowed in the comments to help prevent future security issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee879d9 and 4ebd799.

📒 Files selected for processing (1)
  • examples/tests/vendor.yaml (1 hunks)
🔇 Additional comments (1)
examples/tests/vendor.yaml (1)

Line range hint 1-7: Excellent test coverage! This file serves multiple test scenarios 🎯

The comment block at the top documents various test commands, making this file an excellent test fixture for the URI changes. It covers:

  • Basic vendor pull
  • Component-specific pulls
  • Tag-based filtering

examples/tests/vendor.yaml Outdated Show resolved Hide resolved
Comment on lines 646 to 658
if strings.Contains(uri, "..") {
return fmt.Errorf("URI cannot contain path traversal sequences")
}
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test for vendoring from:

../../demo-library/weather

Copy link
Member

Choose a reason for hiding this comment

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

add it to example/tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@osterman @aknysh
To test the vendor functionality, I reviewed the process and observed that it does not break even if there are errors. However, simply running the vendor pull command is not sufficient as a test.
Instead, there should be specific test cases that validate the process, including counting the vendor files to ensure accuracy. For example, we should test the vendor process on Windows to confirm it does not fail or break. Currently, the process only logs the outcome without actually vendoring any files, which is not reliable for testing purposes

Copy link
Member

Choose a reason for hiding this comment

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

Ok, can you add some proper tests for this then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

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: 0

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

515-523: Enhance error handling for URL parsing

The URL parsing error is silently ignored, which could mask potential issues. Consider handling the error explicitly or logging it for debugging purposes.

-		u, err := url.Parse(*uri)
-		if err == nil && u.Scheme != "" {
+		if parsedURL, err := url.Parse(*uri); err == nil && parsedURL.Scheme != "" {
+			if parsedURL.Scheme == "file" {
+				trimmedPath := strings.TrimPrefix(filepath.ToSlash(parsedURL.Path), "/")
+				*uri = filepath.Clean(trimmedPath)
+				useLocalFileSystem = true
+			}
+		} else if err != nil {
+			u.LogTrace(atmosConfig, fmt.Sprintf("URL parsing warning: %v", err))
+		}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 521ba3b and a7072ed.

📒 Files selected for processing (2)
  • internal/exec/vendor_model.go (2 hunks)
  • internal/exec/vendor_utils.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/vendor_model.go
🔇 Additional comments (4)
internal/exec/vendor_utils.go (4)

510-515: LGTM! Path handling improvements

The changes to handle absolute paths and join them with the vendor config path look good. This addresses the previous review comments about supporting relative paths.


593-594: LGTM! Consistent path handling

The use of filepath.ToSlash ensures consistent path separators across different platforms.


Line range hint 646-664: Verify security implications of relaxed URI validation

The simplified URI validation removes checks for path traversal sequences (..). While this allows for relative paths as requested, we should ensure that path traversal is properly handled during the actual file operations to prevent unauthorized access to system files.

Let's verify the path handling in the codebase:

✅ Verification successful

Based on the results, I can see extensive use of filepath.Clean, filepath.Abs, and proper path handling throughout the codebase. Let me verify the specific file operations:


Path traversal is properly handled, warrior! The codebase is secure.

The codebase demonstrates robust path handling practices:

  • All file paths are cleaned using filepath.Clean before operations
  • File names are sanitized using sanitizeFileName function
  • Absolute paths are resolved using filepath.Abs
  • File operations are performed after proper path validation

The removal of path traversal checks from URI validation is safe because:

  1. The codebase uses filepath.Join for path construction
  2. File operations are performed after sanitization
  3. Target paths are properly constructed and validated before operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for path traversal handling in file operations
echo "Checking for path normalization and validation..."
rg -A 3 "filepath\.(Clean|Abs|Join|EvalSymlinks)" 

# Check for potential file access outside intended directories
echo "Checking file access patterns..."
ast-grep --pattern 'os.(Open|Create|ReadFile|WriteFile|Remove|RemoveAll)($path)'

Length of output: 35394


Script:

#!/bin/bash
# Check for file operations in vendor_utils.go and related files
echo "Checking file operations in vendor-related code..."
rg -A 3 "os\.(Open|Create|ReadFile|WriteFile|Remove|RemoveAll)" internal/exec/vendor_utils.go internal/exec/vendor_component_utils.go

# Check for path sanitization in vendor-related code
echo "Checking path sanitization..."
rg -A 3 "sanitize(File|Path|Base)" internal/exec/vendor_utils.go internal/exec/vendor_component_utils.go internal/exec/vendor_model.go

Length of output: 2093


510-523: Add test cases for relative path vendoring

Following up on @osterman's previous comments, we should add test cases for relative path vendoring, specifically including the ../../demo-library/weather scenario.

Let's check the existing test coverage:

@osterman osterman added the patch A minor, backward compatible change label Jan 3, 2025
@mergify mergify bot added the conflict This PR has conflicts label Jan 4, 2025
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: 4

🧹 Nitpick comments (3)
examples/tests/test-vendor/atmos.yaml (1)

19-28: Consider using absolute paths for vendor configuration.

While relative paths work, using absolute paths for vendor configurations is generally more secure and explicit. This prevents potential path traversal issues when the configuration is loaded from different working directories.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 19-19: trailing spaces

(trailing-spaces)


[error] 22-22: trailing spaces

(trailing-spaces)


[error] 25-25: trailing spaces

(trailing-spaces)

tests/test_cases.yaml (1)

171-205: Consider adding negative test cases for path traversal prevention

While the test case verifies successful component vendoring, it would be beneficial to add negative test cases that verify the path traversal fix. This ensures the security fix is working as intended.

Consider adding test cases that:

  1. Attempt to use URIs with path traversal sequences (../, ./, etc.)
  2. Verify that such attempts are properly rejected
  3. Confirm appropriate error messages are displayed

Would you like me to help draft these additional test cases?

🧰 Tools
🪛 yamllint (1.35.1)

[error] 171-171: trailing spaces

(trailing-spaces)


[warning] 181-181: wrong indentation: expected 8 but found 10

(indentation)


[warning] 182-182: wrong indentation: expected 8 but found 10

(indentation)


[warning] 183-183: wrong indentation: expected 8 but found 10

(indentation)


[warning] 184-184: wrong indentation: expected 8 but found 10

(indentation)


[warning] 185-185: wrong indentation: expected 8 but found 10

(indentation)


[warning] 187-187: wrong indentation: expected 8 but found 10

(indentation)


[warning] 188-188: wrong indentation: expected 8 but found 10

(indentation)


[warning] 189-189: wrong indentation: expected 8 but found 10

(indentation)


[warning] 190-190: wrong indentation: expected 8 but found 10

(indentation)


[warning] 191-191: wrong indentation: expected 8 but found 10

(indentation)


[warning] 193-193: wrong indentation: expected 8 but found 10

(indentation)


[warning] 194-194: wrong indentation: expected 8 but found 10

(indentation)


[warning] 195-195: wrong indentation: expected 8 but found 10

(indentation)


[warning] 196-196: wrong indentation: expected 8 but found 10

(indentation)


[warning] 197-197: wrong indentation: expected 8 but found 10

(indentation)


[warning] 199-199: wrong indentation: expected 8 but found 10

(indentation)


[warning] 200-200: wrong indentation: expected 8 but found 10

(indentation)


[warning] 201-201: wrong indentation: expected 8 but found 10

(indentation)


[warning] 202-202: wrong indentation: expected 8 but found 10

(indentation)


[warning] 203-203: wrong indentation: expected 8 but found 10

(indentation)

examples/tests/test-vendor/test-components/README.md (1)

1-13: Enhance documentation with additional sections

The README provides good basic information but could be more comprehensive.

Consider adding these sections:

  1. Requirements (Terraform version, provider versions)
  2. Example usage block showing the module in action
  3. Notes about API rate limits and any authentication requirements
  4. Link to IPinfo API documentation

Would you like me to help draft these additional sections?

🧰 Tools
🪛 LanguageTool

[uncategorized] ~13-~13: Loose punctuation mark.
Context: ...empty string. ### Outputs - metadata: The data retrieved from IPinfo for the ...

(UNLIKELY_OPENING_PUNCTUATION)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7072ed and 44fa700.

📒 Files selected for processing (11)
  • examples/tests/test-vendor/atmos.yaml (1 hunks)
  • examples/tests/test-vendor/test-components/README.md (1 hunks)
  • examples/tests/test-vendor/test-components/main.tf (1 hunks)
  • examples/tests/test-vendor/test-components/outputs.tf (1 hunks)
  • examples/tests/test-vendor/test-components/providers.tf (1 hunks)
  • examples/tests/test-vendor/test-components/variables.tf (1 hunks)
  • examples/tests/test-vendor/test-components/versions.tf (1 hunks)
  • examples/tests/test-vendor/vendor.yaml (1 hunks)
  • internal/exec/vendor_component_utils.go (2 hunks)
  • tests/cli_test.go (5 hunks)
  • tests/test_cases.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • examples/tests/test-vendor/test-components/providers.tf
  • examples/tests/test-vendor/test-components/versions.tf
🧰 Additional context used
🪛 yamllint (1.35.1)
examples/tests/test-vendor/atmos.yaml

[error] 19-19: trailing spaces

(trailing-spaces)


[error] 22-22: trailing spaces

(trailing-spaces)


[error] 25-25: trailing spaces

(trailing-spaces)


[warning] 37-37: wrong indentation: expected 2 but found 0

(indentation)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)

tests/test_cases.yaml

[error] 171-171: trailing spaces

(trailing-spaces)


[warning] 181-181: wrong indentation: expected 8 but found 10

(indentation)


[warning] 182-182: wrong indentation: expected 8 but found 10

(indentation)


[warning] 183-183: wrong indentation: expected 8 but found 10

(indentation)


[warning] 184-184: wrong indentation: expected 8 but found 10

(indentation)


[warning] 185-185: wrong indentation: expected 8 but found 10

(indentation)


[warning] 187-187: wrong indentation: expected 8 but found 10

(indentation)


[warning] 188-188: wrong indentation: expected 8 but found 10

(indentation)


[warning] 189-189: wrong indentation: expected 8 but found 10

(indentation)


[warning] 190-190: wrong indentation: expected 8 but found 10

(indentation)


[warning] 191-191: wrong indentation: expected 8 but found 10

(indentation)


[warning] 193-193: wrong indentation: expected 8 but found 10

(indentation)


[warning] 194-194: wrong indentation: expected 8 but found 10

(indentation)


[warning] 195-195: wrong indentation: expected 8 but found 10

(indentation)


[warning] 196-196: wrong indentation: expected 8 but found 10

(indentation)


[warning] 197-197: wrong indentation: expected 8 but found 10

(indentation)


[warning] 199-199: wrong indentation: expected 8 but found 10

(indentation)


[warning] 200-200: wrong indentation: expected 8 but found 10

(indentation)


[warning] 201-201: wrong indentation: expected 8 but found 10

(indentation)


[warning] 202-202: wrong indentation: expected 8 but found 10

(indentation)


[warning] 203-203: wrong indentation: expected 8 but found 10

(indentation)

🪛 LanguageTool
examples/tests/test-vendor/test-components/README.md

[uncategorized] ~13-~13: Loose punctuation mark.
Context: ...empty string. ### Outputs - metadata: The data retrieved from IPinfo for the ...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (12)
tests/cli_test.go (5)

7-8: Good migration from ioutil to io.
This change aligns with modern Go practices.


43-49: Properly handling file opening and reading.
Shifting from ReadFile to explicit opens with defer f.Close() is elegant and safer for error diagnostics.


179-179: Enhanced visibility into command failures.
Including stderr in test logs provides valuable debugging info.


225-232: Better file existence checking with absolute paths.
This approach avoids ambiguity if relative paths shift.


242-248: Reading file contents via io.ReadAll.
Consistency in file operations is beneficial and clarifies errors.

internal/exec/vendor_component_utils.go (2)

8-8: Added dependency on net/url.
This is necessary for robust URI parsing.


248-255: Support for file scheme URLs.
Discarding the leading slash and marking the flag is a nice refinement for local files.

examples/tests/test-vendor/test-components/variables.tf (1)

1-5: New optional IP address variable.
This variable provides flexible input for external queries. Great addition.

examples/tests/test-vendor/test-components/outputs.tf (1)

1-4: Added metadata output.
The JSON decode step is a convenient approach for leveraging external data.

examples/tests/test-vendor/vendor.yaml (2)

32-38: LGTM: Proper version pinning in Git URL.

The Git URL correctly uses ?ref={{.Version}} to pin the version, which is a good security practice to prevent supply chain attacks.


24-26: ⚠️ Potential issue

Validate local file paths for potential security risks.

The file:/// scheme could be vulnerable to path traversal attacks. Ensure that the path is properly validated and normalized before use.

✅ Verification successful

The previous search was too specific. Let's broaden our search to understand the context better and check for any potential security measures around file paths.


Let's examine how the codebase handles file:/// URIs and component sources to understand the security measures in place.


Let's look at how the config sources are processed to understand the security measures for file:/// URIs.


Let's examine how components and their sources are validated to understand the security measures in place.


Let's examine how URIs are validated and if there are any path sanitization measures in place.


File paths are properly validated and sanitized

After examining the codebase, I can confirm that the file:/// scheme in the vendor configuration is properly handled with multiple security measures:

  • The URI is validated through validateURI function which checks for malformed inputs
  • File paths are sanitized using sanitizeFileName which handles unsafe characters
  • Local file paths are processed through determineSourceType which properly normalizes paths
  • The implementation uses filepath.Clean and filepath.ToSlash for path normalization
  • File operations are restricted to the configured base paths
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the file path contains any suspicious patterns
rg -l "file:///(\.\.|\~)" .

Length of output: 29


Script:

#!/bin/bash
# Let's check for any file:/// URIs in the codebase to analyze their usage
rg -p "file:///" .

# Also check for path validation or sanitization logic
rg -p -g '*.{go,rs,js,ts,py}' "(sanitize|validate|normalize).*path" .

Length of output: 1952


Script:

#!/bin/bash
# Let's check the implementation of component source handling
ast-grep --pattern 'func $$$($$$) {
  $$$
  file:///$$$
  $$$
}'

# Also check for any URI/path processing logic
rg -p "func.*[Pp]rocess.*(?:URI|Source|Path)" .

Length of output: 333


Script:

#!/bin/bash
# Let's examine the config sources processing implementation
cat ./internal/exec/config_sources_utils.go

# And check for any component source validation
rg -p "func.*ValidateComponent" .

Length of output: 17076


Script:

#!/bin/bash
# Let's check the component validation implementation
cat ./internal/exec/validate_component.go

# And check for any URI handling or source validation
rg -p "func.*[Vv]alidate.*(?:URI|Source|Path)" .

Length of output: 7071


Script:

#!/bin/bash
# Let's check the URI validation implementation
cat ./internal/exec/vendor_utils.go

# And check for any file path handling utilities
rg -p "func.*(?:NormalizePath|CleanPath|SanitizePath)" .

Length of output: 21392

examples/tests/test-vendor/test-components/README.md (1)

Line range hint 171-205: Verify test coverage for URI validation changes

The PR aims to fix path traversal in URIs, but the current test only verifies successful cases. To ensure comprehensive coverage:

  1. Add test cases that explicitly verify URI validation
  2. Include examples from issue Support Path Traversals in Vendoring #888 in the test suite

Let's check the test coverage:

🧰 Tools
🪛 LanguageTool

[uncategorized] ~13-~13: Loose punctuation mark.
Context: ...empty string. ### Outputs - metadata: The data retrieved from IPinfo for the ...

(UNLIKELY_OPENING_PUNCTUATION)

Comment on lines +36 to +40
commands:
- name: "test"
description: "Run all tests"
steps:
- atmos vendor pull --everything
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Consider using explicit component selection instead of --everything flag

The --everything flag in the test command will pull all defined components:

  • github/stargazers (demo, github tags)
  • test-components (demo tag)
  • weather (demo tag)
  • my-vpc1 (no tags)

Instead of using --everything, consider one of these more explicit approaches:

  • Use --tags demo to pull all demo components
  • List specific components: atmos vendor pull -c github/stargazers -c weather
  • Create a separate test command for each component group you need to test

This provides better control over which components are pulled during testing and makes the dependencies more explicit.

🔗 Analysis chain

Review security implications of the --everything flag.

The --everything flag in the test command could potentially pull all vendor components without discrimination. Consider being more explicit about which components to test.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check what components would be pulled with --everything flag
atmos vendor pull --dry-run --everything

Length of output: 138


Script:

#!/bin/bash
# Let's check the vendor configuration and related files
fd vendor -t f

# Check for any documentation or configuration related to vendor components
rg -i "vendor" -g "*.{md,yaml,yml}" -A 3 -B 3

Length of output: 34075


Script:

#!/bin/bash
# Let's check the vendor.yaml file in the test-vendor directory to understand the configuration
cat examples/tests/test-vendor/vendor.yaml

# Let's also check if there are any specific components or tags defined
rg "component:|tags:" examples/tests/test-vendor/vendor.yaml -A 2

Length of output: 2092

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 37-37: wrong indentation: expected 2 but found 0

(indentation)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)

examples/tests/test-vendor/vendor.yaml Show resolved Hide resolved
tests/test_cases.yaml Outdated Show resolved Hide resolved
@mergify mergify bot removed the conflict This PR has conflicts label Jan 4, 2025
@haitham911 haitham911 requested a review from osterman January 4, 2025 16:53
Copy link

mergify bot commented Jan 8, 2025

💥 This pull request now has conflicts. Could you fix it @haitham911? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Jan 8, 2025
@aknysh
Copy link
Member

aknysh commented Jan 17, 2025

@haitham911 please resolve the conflicts

@mergify mergify bot removed the conflict This PR has conflicts label Jan 20, 2025
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: 0

🧹 Nitpick comments (2)
tests/cli_test.go (2)

460-465: Consider enhancing error message for directory change failure.

The error message could be more descriptive to help with debugging.

-    t.Fatalf("Failed to change back to the starting directory: %v", err)
+    t.Fatalf("Failed to restore working directory to '%s': %v", startingDir, err)

596-603: Improve error handling for file path resolution.

The error handling for absolute path resolution could be more robust.

-    if err != nil {
-        log.Println(err)
-        return false
-    }
+    if err != nil {
+        t.Errorf("Failed to resolve absolute path for '%s': %v", file, err)
+        return false
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 713ab4b and e82dc28.

📒 Files selected for processing (12)
  • examples/tests/test-vendor/atmos.yaml (1 hunks)
  • examples/tests/test-vendor/test-components/README.md (1 hunks)
  • examples/tests/test-vendor/test-components/main.tf (1 hunks)
  • examples/tests/test-vendor/test-components/outputs.tf (1 hunks)
  • examples/tests/test-vendor/test-components/providers.tf (1 hunks)
  • examples/tests/test-vendor/test-components/variables.tf (1 hunks)
  • examples/tests/test-vendor/test-components/versions.tf (1 hunks)
  • examples/tests/test-vendor/vendor.yaml (1 hunks)
  • internal/exec/vendor_component_utils.go (2 hunks)
  • internal/exec/vendor_model.go (1 hunks)
  • internal/exec/vendor_utils.go (3 hunks)
  • tests/cli_test.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • examples/tests/test-vendor/test-components/providers.tf
  • examples/tests/test-vendor/test-components/variables.tf
  • examples/tests/test-vendor/test-components/outputs.tf
  • examples/tests/test-vendor/test-components/versions.tf
  • examples/tests/test-vendor/test-components/main.tf
  • internal/exec/vendor_model.go
  • examples/tests/test-vendor/vendor.yaml
👮 Files not reviewed due to content moderation or server errors (4)
  • examples/tests/test-vendor/test-components/README.md
  • examples/tests/test-vendor/atmos.yaml
  • internal/exec/vendor_component_utils.go
  • internal/exec/vendor_utils.go
🧰 Additional context used
🪛 yamllint (1.35.1)
examples/tests/test-vendor/atmos.yaml

[error] 19-19: trailing spaces

(trailing-spaces)


[error] 22-22: trailing spaces

(trailing-spaces)


[error] 25-25: trailing spaces

(trailing-spaces)


[warning] 37-37: wrong indentation: expected 2 but found 0

(indentation)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)

🪛 LanguageTool
examples/tests/test-vendor/test-components/README.md

[uncategorized] ~13-~13: Loose punctuation mark.
Context: ...empty string. ### Outputs - metadata: The data retrieved from IPinfo for the ...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: [mock-macos] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-macos] examples/demo-vendoring
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-context
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: [mock-windows] examples/demo-atlantis
  • GitHub Check: [mock-linux] tests/fixtures/scenarios/complete
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: Summary
🔇 Additional comments (1)
tests/cli_test.go (1)

89-95: Good enhancement to file handling!

The switch to explicit file opening with proper error handling improves robustness.

Copy link

mergify bot commented Jan 20, 2025

💥 This pull request now has conflicts. Could you fix it @haitham911? 🙏

@mergify mergify bot added conflict This PR has conflicts and removed conflict This PR has conflicts labels Jan 20, 2025
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 (3)
examples/tests/test-vendor/test-components/README.md (1)

13-13: Enhance output documentation and fix punctuation.

Add a period at the end of the line for consistency. Consider adding:

  • Example of the JSON structure returned in the metadata
  • Description of key fields in the response
-- `metadata`: The data retrieved from IPinfo for the specified IP address, in JSON format.
++ `metadata`: The data retrieved from IPinfo for the specified IP address, in JSON format. Example:
++ ```json
++ {
++   "ip": "8.8.8.8",
++   "hostname": "dns.google",
++   "city": "Mountain View",
++   "region": "California",
++   "country": "US",
++   "loc": "37.4056,-122.0775",
++   "org": "AS15169 Google LLC",
++   "postal": "94043",
++   "timezone": "America/Los_Angeles"
++ }
++ ```
🧰 Tools
🪛 LanguageTool

[uncategorized] ~13-~13: Loose punctuation mark.
Context: ...empty string. ### Outputs - metadata: The data retrieved from IPinfo for the ...

(UNLIKELY_OPENING_PUNCTUATION)

examples/tests/test-vendor/atmos.yaml (2)

19-28: Fix trailing spaces in the vendor section.

Remove trailing spaces from lines 19, 22, and 25 to maintain consistent formatting.

-vendor:  
+vendor:
 # Single file
-base_path: "./vendor.yaml"
+base_path: "./vendor.yaml"
 
 # Directory with multiple files
-#base_path: "./vendor"
+#base_path: "./vendor"
🧰 Tools
🪛 yamllint (1.35.1)

[error] 19-19: trailing spaces

(trailing-spaces)


[error] 22-22: trailing spaces

(trailing-spaces)


[error] 25-25: trailing spaces

(trailing-spaces)


36-40: Fix YAML indentation.

The indentation is inconsistent. The commands list items should be properly indented.

 commands:
-- name: "test"
-  description: "Run all tests"
-  steps:
-  - atmos vendor pull --everything
+  - name: "test"
+    description: "Run all tests"
+    steps:
+      - atmos vendor pull --everything
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 37-37: wrong indentation: expected 2 but found 0

(indentation)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e82dc28 and 063f955.

📒 Files selected for processing (14)
  • examples/tests/test-vendor/atmos.yaml (1 hunks)
  • examples/tests/test-vendor/test-components/README.md (1 hunks)
  • examples/tests/test-vendor/test-components/main.tf (1 hunks)
  • examples/tests/test-vendor/test-components/outputs.tf (1 hunks)
  • examples/tests/test-vendor/test-components/providers.tf (1 hunks)
  • examples/tests/test-vendor/test-components/variables.tf (1 hunks)
  • examples/tests/test-vendor/test-components/versions.tf (1 hunks)
  • examples/tests/test-vendor/vendor.yaml (1 hunks)
  • internal/exec/vendor_component_utils.go (2 hunks)
  • internal/exec/vendor_model.go (1 hunks)
  • internal/exec/vendor_utils.go (5 hunks)
  • tests/cli_test.go (5 hunks)
  • tests/fixtures/scenarios/complete/vendor.yaml (1 hunks)
  • tests/test-cases/demo-stacks.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • examples/tests/test-vendor/test-components/variables.tf
  • examples/tests/test-vendor/test-components/outputs.tf
  • examples/tests/test-vendor/test-components/providers.tf
  • examples/tests/test-vendor/test-components/versions.tf
  • examples/tests/test-vendor/test-components/main.tf
  • internal/exec/vendor_model.go
  • tests/cli_test.go
  • examples/tests/test-vendor/vendor.yaml
🧰 Additional context used
🪛 GitHub Check: Build (macos-latest, macos)
internal/exec/vendor_utils.go

[failure] 655-655:
CustomGitHubDetector redeclared in this block


[failure] 660-660:
method CustomGitHubDetector.Detect already declared at internal/exec/go_getter_utils.go:76:32


[failure] 726-726:
RegisterCustomDetectors redeclared in this block

🪛 GitHub Check: Build (windows-latest, windows)
internal/exec/vendor_utils.go

[failure] 655-655:
CustomGitHubDetector redeclared in this block


[failure] 660-660:
method CustomGitHubDetector.Detect already declared at internal\exec\go_getter_utils.go:76:32


[failure] 726-726:
RegisterCustomDetectors redeclared in this block

🪛 GitHub Check: Build (ubuntu-latest, linux)
internal/exec/vendor_utils.go

[failure] 655-655:
CustomGitHubDetector redeclared in this block


[failure] 660-660:
method CustomGitHubDetector.Detect already declared at internal/exec/go_getter_utils.go:76:32


[failure] 726-726:
RegisterCustomDetectors redeclared in this block

🪛 GitHub Actions: Tests
internal/exec/vendor_utils.go

[error] 655-655: CustomGitHubDetector redeclared in this block

🪛 yamllint (1.35.1)
examples/tests/test-vendor/atmos.yaml

[error] 19-19: trailing spaces

(trailing-spaces)


[error] 22-22: trailing spaces

(trailing-spaces)


[error] 25-25: trailing spaces

(trailing-spaces)


[warning] 37-37: wrong indentation: expected 2 but found 0

(indentation)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)

🪛 LanguageTool
examples/tests/test-vendor/test-components/README.md

[uncategorized] ~13-~13: Loose punctuation mark.
Context: ...empty string. ### Outputs - metadata: The data retrieved from IPinfo for the ...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (6)
examples/tests/test-vendor/atmos.yaml (1)

36-40: Consider using explicit component selection instead of --everything flag.

The --everything flag in the test command will pull all defined components. Instead of using --everything, consider one of these more explicit approaches:

  • Use --tags demo to pull all demo components
  • List specific components: atmos vendor pull -c github/stargazers -c weather
  • Create a separate test command for each component group you need to test

This provides better control over which components are pulled during testing and makes the dependencies more explicit.

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 37-37: wrong indentation: expected 2 but found 0

(indentation)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)

tests/fixtures/scenarios/complete/vendor.yaml (1)

48-48: LGTM! Improved source URL format.

The source URL format has been updated to use the explicit git::https prefix, which aligns with the enhanced URI validation and handling.

tests/test-cases/demo-stacks.yaml (1)

134-191: LGTM! Comprehensive test coverage added.

The new test cases effectively validate:

  1. Custom command functionality with and without arguments
  2. Vendor pull command execution and file existence verification

This addresses the previous request for proper testing of the vendor functionality.

internal/exec/vendor_component_utils.go (2)

252-259: LGTM! Enhanced URI handling for file:// schema.

The addition of file:// schema support improves the flexibility of the vendoring system while maintaining proper path handling.


Line range hint 571-572: LGTM! Improved cross-platform path handling.

The use of filepath.ToSlash ensures consistent path handling across different operating systems.

internal/exec/vendor_utils.go (1)

626-640: LGTM! Robust URI validation.

The new validateURI function provides comprehensive validation including:

  • Empty URI check
  • Space character check
  • OCI URI format validation

Comment on lines +5 to +6
## Usage

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add usage examples and prerequisites.

The Usage section would benefit from:

  • A complete example showing how to use this module
  • Prerequisites (e.g., required provider configuration)
  • Information about IPinfo API rate limits and authentication requirements
  • Version compatibility information

Here's a suggested structure:

## Usage

### Prerequisites
- Terraform >= 0.13
- IPinfo API token (if required)

### Provider Configuration
```hcl
provider "http" {}

Example Usage

module "ipinfo" {
  source = "path/to/module"
  
  ip_address = "8.8.8.8"  # Optional: Specify an IP address
}

output "ip_metadata" {
  value = module.ipinfo.metadata
}

<!-- This is an auto-generated comment by CodeRabbit -->

Comment on lines 652 to 733
// CustomGitHubDetector intercepts GitHub URLs and transforms them
// into something like git::https://<token>@github.com/... so we can
// do a git-based clone with a token.
type CustomGitHubDetector struct {
AtmosConfig schema.AtmosConfiguration
}

// Detect implements the getter.Detector interface for go-getter v1.
func (d *CustomGitHubDetector) Detect(src, _ string) (string, bool, error) {
if len(src) == 0 {
return "", false, nil
}

if !strings.Contains(src, "://") {
src = "https://" + src
}

parsedURL, err := url.Parse(src)
if err != nil {
u.LogDebug(d.AtmosConfig, fmt.Sprintf("Failed to parse URL %q: %v\n", src, err))
return "", false, fmt.Errorf("failed to parse URL %q: %w", src, err)
}

if strings.ToLower(parsedURL.Host) != "github.com" {
u.LogDebug(d.AtmosConfig, fmt.Sprintf("Host is %q, not 'github.com', skipping token injection\n", parsedURL.Host))
return "", false, nil
}

parts := strings.SplitN(parsedURL.Path, "/", 4)
if len(parts) < 3 {
u.LogDebug(d.AtmosConfig, fmt.Sprintf("URL path %q doesn't look like /owner/repo\n", parsedURL.Path))
return "", false, fmt.Errorf("invalid GitHub URL %q", parsedURL.Path)
}

atmosGitHubToken := os.Getenv("ATMOS_GITHUB_TOKEN")
gitHubToken := os.Getenv("GITHUB_TOKEN")

var usedToken string
var tokenSource string

// 1. If ATMOS_GITHUB_TOKEN is set, always use that
if atmosGitHubToken != "" {
usedToken = atmosGitHubToken
tokenSource = "ATMOS_GITHUB_TOKEN"
u.LogDebug(d.AtmosConfig, "ATMOS_GITHUB_TOKEN is set\n")
} else {
// 2. Otherwise, only inject GITHUB_TOKEN if cfg.Settings.InjectGithubToken == true
if d.AtmosConfig.Settings.InjectGithubToken && gitHubToken != "" {
usedToken = gitHubToken
tokenSource = "GITHUB_TOKEN"
u.LogTrace(d.AtmosConfig, "InjectGithubToken=true and GITHUB_TOKEN is set, using it\n")
} else {
u.LogTrace(d.AtmosConfig, "No ATMOS_GITHUB_TOKEN or GITHUB_TOKEN found\n")
}
}

if usedToken != "" {
user := parsedURL.User.Username()
pass, _ := parsedURL.User.Password()
if user == "" && pass == "" {
u.LogDebug(d.AtmosConfig, fmt.Sprintf("Injecting token from %s for %s\n", tokenSource, src))
parsedURL.User = url.UserPassword("x-access-token", usedToken)
} else {
u.LogDebug(d.AtmosConfig, "Credentials found, skipping token injection\n")
}
}

finalURL := "git::" + parsedURL.String()

return finalURL, true, nil
}

// RegisterCustomDetectors prepends the custom detector so it runs before
// the built-in ones. Any code that calls go-getter should invoke this.
func RegisterCustomDetectors(atmosConfig schema.AtmosConfiguration) {
getter.Detectors = append(
[]getter.Detector{
&CustomGitHubDetector{AtmosConfig: atmosConfig},
},
getter.Detectors...,
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix duplicate declarations.

The following entities are already declared in internal/exec/go_getter_utils.go:

  • CustomGitHubDetector struct
  • Detect method
  • RegisterCustomDetectors function

This is causing build failures across all platforms.

Consider:

  1. Moving all GitHub-related code to a single file
  2. Removing the duplicate declarations from this file
🧰 Tools
🪛 GitHub Check: Build (macos-latest, macos)

[failure] 655-655:
CustomGitHubDetector redeclared in this block


[failure] 660-660:
method CustomGitHubDetector.Detect already declared at internal/exec/go_getter_utils.go:76:32


[failure] 726-726:
RegisterCustomDetectors redeclared in this block

🪛 GitHub Check: Build (windows-latest, windows)

[failure] 655-655:
CustomGitHubDetector redeclared in this block


[failure] 660-660:
method CustomGitHubDetector.Detect already declared at internal\exec\go_getter_utils.go:76:32


[failure] 726-726:
RegisterCustomDetectors redeclared in this block

🪛 GitHub Check: Build (ubuntu-latest, linux)

[failure] 655-655:
CustomGitHubDetector redeclared in this block


[failure] 660-660:
method CustomGitHubDetector.Detect already declared at internal/exec/go_getter_utils.go:76:32


[failure] 726-726:
RegisterCustomDetectors redeclared in this block

🪛 GitHub Actions: Tests

[error] 655-655: CustomGitHubDetector redeclared in this block

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/vendor_utils.go (1)

388-388: Adjust path handling for cross-platform compatibility.

Using filepath.ToSlash on path components before filepath.Join may cause incorrect path separators on Windows systems. It's advisable to join the paths first and then normalize if necessary.

Apply this diff to modify the path handling:

-targetPath := filepath.Join(filepath.ToSlash(vendorConfigFilePath), filepath.ToSlash(target))
+targetPath := filepath.Join(vendorConfigFilePath, target)
+targetPath = filepath.ToSlash(targetPath)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 063f955 and 201b521.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (5 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
internal/exec/vendor_utils.go

625-625: func validateURI is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: Summary

internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
Comment on lines 625 to 639
func validateURI(uri string) error {
if uri == "" {
return fmt.Errorf("URI cannot be empty")
}
if strings.Contains(uri, " ") {
return fmt.Errorf("URI cannot contain spaces")
}
// Validate scheme-specific format
if strings.HasPrefix(uri, "oci://") {
if !strings.Contains(uri[6:], "/") {
return fmt.Errorf("invalid OCI URI format")
}
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix function naming inconsistency to prevent compilation errors.

The function validateURI is defined but not used, as indicated by static analysis. Additionally, there is a call to ValidateURI(uri) with an uppercase 'V', which does not match the function name. In Go, function names are case-sensitive. Please ensure the function name matches the usage to avoid undefined function errors.

Apply this diff to fix the function name:

-func validateURI(uri string) error {
+func ValidateURI(uri string) error {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func validateURI(uri string) error {
if uri == "" {
return fmt.Errorf("URI cannot be empty")
}
if strings.Contains(uri, " ") {
return fmt.Errorf("URI cannot contain spaces")
}
// Validate scheme-specific format
if strings.HasPrefix(uri, "oci://") {
if !strings.Contains(uri[6:], "/") {
return fmt.Errorf("invalid OCI URI format")
}
}
return nil
}
func ValidateURI(uri string) error {
if uri == "" {
return fmt.Errorf("URI cannot be empty")
}
if strings.Contains(uri, " ") {
return fmt.Errorf("URI cannot contain spaces")
}
// Validate scheme-specific format
if strings.HasPrefix(uri, "oci://") {
if !strings.Contains(uri[6:], "/") {
return fmt.Errorf("invalid OCI URI format")
}
}
return nil
}
🧰 Tools
🪛 golangci-lint (1.62.2)

625-625: func validateURI is unused

(unused)

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: 0

🔭 Outside diff range comments (2)
internal/exec/go_getter_utils.go (2)

Line range hint 89-117: Review security implications of debug logging.

The debug logging could potentially expose sensitive information in log files. Consider:

  1. Redacting tokens and credentials from URLs in debug logs
  2. Limiting the token source information in logs
-			u.LogDebug(d.AtmosConfig, fmt.Sprintf("Injecting token from %s for %s\n", tokenSource, src))
+			u.LogDebug(d.AtmosConfig, "Injecting authentication token\n")

Consider adding download size limits for enhanced security

The codebase properly implements path cleaning for local filesystem operations, but could benefit from explicit size limits for downloads. While go-getter handles basic security, consider adding:

  • Maximum file size configuration in AtmosConfiguration
  • Size validation before processing downloaded content
🔗 Analysis chain

Line range hint 156-187: Verify security measures for file downloads.

While the scheme support is well documented, please verify:

  1. File scheme path validation for directory traversal
  2. Download size limits to prevent resource exhaustion
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential directory traversal validation in the codebase
rg -l "path\.Clean|filepath\.Clean" .

# Look for download size limit implementations
rg -l "MaxSize|size.*limit|limit.*size" .

Length of output: 251


Script:

#!/bin/bash
# Check path cleaning implementation in the relevant files
rg -A 5 "filepath\.Clean|path\.Clean" ./internal/exec/vendor_utils.go ./internal/exec/vendor_component_utils.go

# Check go-getter configuration and usage patterns
ast-grep --pattern 'getter.Client{$$$}'

Length of output: 2240

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

Line range hint 22-54: Consider enhancing URI validation for better security.

The validation is solid, but could be strengthened further:

  1. Consider using path.Clean for more robust path traversal prevention
  2. Add validation for encoded path traversal sequences (%2e%2e)
  3. Document the rationale for the 2048 character limit
 func ValidateURI(uri string) error {
 	if uri == "" {
 		return fmt.Errorf("URI cannot be empty")
 	}
+	// 2048 is a common limit for URIs in many systems and browsers
 	if len(uri) > 2048 {
 		return fmt.Errorf("URI exceeds maximum length of 2048 characters")
 	}
-	if strings.Contains(uri, "..") {
+	// Check for both raw and encoded path traversal sequences
+	if strings.Contains(uri, "..") || strings.Contains(strings.ToLower(uri), "%2e%2e") {
 		return fmt.Errorf("URI cannot contain path traversal sequences")
 	}
+	// Clean the path to catch more traversal attempts
+	if cleaned := path.Clean(uri); strings.Contains(cleaned, "..") {
+		return fmt.Errorf("URI contains invalid path traversal after cleaning")
+	}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 201b521 and 46edee4.

📒 Files selected for processing (2)
  • internal/exec/go_getter_utils.go (1 hunks)
  • tests/test-cases/demo-stacks.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test-cases/demo-stacks.yaml
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: [lint] quick-start-advanced
  • GitHub Check: [lint] demo-context
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Summary
🔇 Additional comments (1)
internal/exec/go_getter_utils.go (1)

64-64: LGTM! Clean addition of file scheme support.

The addition of the "file" scheme aligns perfectly with the PR objectives and maintains the existing validation pattern.

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: 0

🧹 Nitpick comments (2)
internal/exec/vendor_utils.go (2)

390-390: Consider using filepath.Clean before joining paths.

While filepath.ToSlash helps with cross-platform compatibility, adding filepath.Clean would provide additional protection against path traversal attempts.

-			targetPath := filepath.Join(filepath.ToSlash(vendorConfigFilePath), filepath.ToSlash(target))
+			targetPath := filepath.Join(filepath.ToSlash(filepath.Clean(vendorConfigFilePath)), filepath.ToSlash(filepath.Clean(target)))

572-573: Consider using path/filepath for consistent path handling.

While filepath.ToSlash works here, consider using path/filepath package's functions consistently throughout the path handling logic for better maintainability.

-		tempDir = filepath.ToSlash(tempDir)
-		src = filepath.ToSlash(src)
+		tempDir = filepath.Clean(filepath.ToSlash(tempDir))
+		src = filepath.Clean(filepath.ToSlash(src))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d0490de and 4b3c662.

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

367-372: Good addition of URI validation!

The conditional validation ensures that only non-local URIs are validated, which is a secure approach to handling different types of sources.


525-533: Verify file URI handling across platforms.

The file URI handling looks good, but we should verify it works correctly on Windows paths. Let's check if the code handles Windows-style paths properly.

✅ Verification successful

File URI handling is properly implemented for cross-platform compatibility 💪

The implementation is robust and platform-agnostic due to:

  • Consistent use of filepath.ToSlash for path separator normalization
  • Proper path cleaning with filepath.Clean
  • Correct handling of the file:// scheme
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for Windows-style paths in the codebase
rg -l "file://[A-Za-z]:\\\\" .

# Check for any file URI tests
rg -l "file://" "**/*_test.go"

Length of output: 114


Script:

#!/bin/bash
# Search for test files properly
fd "_test\.go$" -x rg -l "file://" {}

# Look for file URI handling patterns
rg -g "*.go" -l "url\.Parse.*file://"

# Check for filepath usage patterns in the same file
rg -g "vendor_utils.go" "filepath\.(Clean|ToSlash)" -A 2 -B 2

Length of output: 1927

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

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

367-375: LGTM! Good security check for URI validation.

The conditional validation and specific handling of path traversal sequences enhance security. Consider making the error message more specific about URI format requirements.

-					return fmt.Errorf("Invalid URI '%s': %w. Please ensure the source is a valid local path or a properly formatted URI.", uri, err)
+					return fmt.Errorf("Invalid URI '%s': %w. URI must be in format scheme://host/path (e.g., git://github.com/org/repo or https://domain.com/path)", uri, err)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b3c662 and 2f3690f.

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

393-393: LGTM! Robust cross-platform path handling.

The use of filepath.ToSlash ensures consistent path separators across different operating systems.


575-576: LGTM! Consistent path normalization.

The path normalization maintains consistency with the rest of the codebase and ensures reliable path comparisons across platforms.

Comment on lines +523 to +536
if absPath, err := u.JoinAbsolutePathWithPath(filepath.ToSlash(vendorConfigFilePath), *uri); err == nil {
uri = &absPath
useLocalFileSystem = true
sourceIsLocalFile = u.FileExists(*uri)
}
parsedURL, err := url.Parse(*uri)
if err == nil && parsedURL.Scheme != "" {
if parsedURL.Scheme == "file" {
trimmedPath := strings.TrimPrefix(filepath.ToSlash(parsedURL.Path), "/")
*uri = filepath.Clean(trimmedPath)
useLocalFileSystem = true
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider handling URL parsing errors.

While the URL parsing and file schema handling is good, the error from url.Parse is silently ignored. This could mask potential issues.

 		parsedURL, err := url.Parse(*uri)
-		if err == nil && parsedURL.Scheme != "" {
+		if err != nil {
+			return useOciScheme, useLocalFileSystem, sourceIsLocalFile
+		}
+		if parsedURL.Scheme != "" {
 			if parsedURL.Scheme == "file" {
 				trimmedPath := strings.TrimPrefix(filepath.ToSlash(parsedURL.Path), "/")
 				*uri = filepath.Clean(trimmedPath)

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member

Choose a reason for hiding this comment

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

This directory has moved to tests/fixtures/scenarios

- name: atmos_vendor_pull
enabled: true
description: "Ensure atmos vendor pull command executes without errors and files are present."
workdir: "../examples/tests/test-vendor/"
Copy link
Member

Choose a reason for hiding this comment

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

Use test fixtures instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Change that restores intended behavior patch A minor, backward compatible change triage Needs triage
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Support Path Traversals in Vendoring
3 participants