-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe 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
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
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 |
There was a problem hiding this 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 componentsWhile the new format with
git::https://
is more secure, we should maintain consistency. Theweather
andipinfo
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
📒 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
There was a problem hiding this 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
📒 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
internal/exec/vendor_utils.go
Outdated
if strings.Contains(uri, "..") { | ||
return fmt.Errorf("URI cannot contain path traversal sequences") | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this 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 parsingThe 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
📒 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:
- The codebase uses
filepath.Join
for path construction - File operations are performed after sanitization
- 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:
There was a problem hiding this 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 preventionWhile 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:
- Attempt to use URIs with path traversal sequences (
../
,./
, etc.)- Verify that such attempts are properly rejected
- 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 sectionsThe README provides good basic information but could be more comprehensive.
Consider adding these sections:
- Requirements (Terraform version, provider versions)
- Example usage block showing the module in action
- Notes about API rate limits and any authentication requirements
- 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
📒 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 fromioutil
toio
.
This change aligns with modern Go practices.
43-49
: Properly handling file opening and reading.
Shifting fromReadFile
to explicit opens withdefer 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 viaio.ReadAll
.
Consistency in file operations is beneficial and clarifies errors.internal/exec/vendor_component_utils.go (2)
8-8
: Added dependency onnet/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 issueValidate 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
andfilepath.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 changesThe PR aims to fix path traversal in URIs, but the current test only verifies successful cases. To ensure comprehensive coverage:
- Add test cases that explicitly verify URI validation
- 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)
commands: | ||
- name: "test" | ||
description: "Run all tests" | ||
steps: | ||
- atmos vendor pull --everything |
There was a problem hiding this comment.
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)
💥 This pull request now has conflicts. Could you fix it @haitham911? 🙏 |
@haitham911 please resolve the conflicts |
713ab4b
to
e82dc28
Compare
There was a problem hiding this 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
📒 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.
💥 This pull request now has conflicts. Could you fix it @haitham911? 🙏 |
d89c75d
to
063f955
Compare
There was a problem hiding this 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
📒 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:
- Custom command functionality with and without arguments
- 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
## Usage | ||
|
There was a problem hiding this comment.
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 -->
internal/exec/vendor_utils.go
Outdated
// 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..., | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix duplicate declarations.
The following entities are already declared in internal/exec/go_getter_utils.go
:
CustomGitHubDetector
structDetect
methodRegisterCustomDetectors
function
This is causing build failures across all platforms.
Consider:
- Moving all GitHub-related code to a single file
- 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
There was a problem hiding this 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 beforefilepath.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
📒 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
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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)
There was a problem hiding this 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:
- Redacting tokens and credentials from URLs in debug logs
- 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:
- File scheme path validation for directory traversal
- 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:
- Consider using
path.Clean
for more robust path traversal prevention- Add validation for encoded path traversal sequences (
%2e%2e
)- 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
📒 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.
There was a problem hiding this 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, addingfilepath.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 usingpath/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
📒 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 2Length of output: 1927
There was a problem hiding this 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
📒 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.
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 | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use test fixtures instead
fix vendor bugs and add test for vendor
references
Summary by CodeRabbit
Release Notes
New Features
Improvements
Testing
Documentation