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 16 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion examples/demo-vendoring/vendor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:

sources:
- component: "github/stargazers"
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}}"
haitham911 marked this conversation as resolved.
Show resolved Hide resolved
version: "main"
targets:
- "components/terraform/{{ .Component }}/{{.Version}}"
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/vendor_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (m *modelVendor) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
version := grayColor.Render(version)
return m, tea.Sequence(
tea.Printf("%s %s %s", mark, pkg.name, version),
tea.Printf("%s %s %s %s", mark, pkg.name, version, errMsg),
tea.Quit,
)
}
Expand Down
18 changes: 0 additions & 18 deletions internal/exec/vendor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,32 +637,14 @@ func validateURI(uri string) error {
if uri == "" {
return fmt.Errorf("URI cannot be empty")
}
// Maximum length check
if len(uri) > 2048 {
return fmt.Errorf("URI exceeds maximum length of 2048 characters")
}
// Add more validation as needed
// Validate URI format
if strings.Contains(uri, "..") {
return fmt.Errorf("URI cannot contain path traversal sequences")
}
Comment on lines -646 to -648
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

if strings.Contains(uri, " ") {
return fmt.Errorf("URI cannot contain spaces")
}
// Validate characters
if strings.ContainsAny(uri, "<>|&;$") {
return fmt.Errorf("URI contains invalid characters")
}
// Validate scheme-specific format
if strings.HasPrefix(uri, "oci://") {
if !strings.Contains(uri[6:], "/") {
return fmt.Errorf("invalid OCI URI format")
}
} else if strings.Contains(uri, "://") {
scheme := strings.Split(uri, "://")[0]
if !isValidScheme(scheme) {
return fmt.Errorf("unsupported URI scheme: %s", scheme)
}
}
return nil
}
Expand Down
Loading