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

Add validation to helm values file path to prevent potential dirtrav vulnerability #3726

Merged
merged 21 commits into from
Jun 7, 2022

Conversation

Szarny
Copy link
Contributor

@Szarny Szarny commented Jun 3, 2022

What this PR does / why we need it:

To prevent potential directory traversal vuln, a mechanism has been added in this PR to restrict the path that can be specified as the Helm values file to the directory inside which the application configuration file exists.

For example, if an attacker specifies the values file path is ../../../../../../path/to/secret.yaml to attempt to illegally render the manifest of an application containing unrelated confidential material that stores on the host where Piped is running will fail because of this mechanism.

Which issue(s) this PR fixes:

Fixes #3719

Does this PR introduce a user-facing change?:

Add validation for paths that can be specified as Helm values file's location.

@Szarny Szarny self-assigned this Jun 3, 2022
@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. resolve symbolic link

// TODO: resolve symbolic link
if !filepath.IsAbs(valueFilePath) {
valueFilePath = filepath.Join(absChartPath, valueFilePath)
}

This was created by todo plugin since "TODO:" was found in a6d49a3 when #3726 was merged. cc: @Szarny.

@Szarny Szarny marked this pull request as ready for review June 7, 2022 06:15
func verifyHelmValueFilePath(appDir, valueFilePath string) error {
url, err := url.Parse(valueFilePath)
if err == nil && url.Scheme != "" {
for _, s := range allowedURLSchemes {
Copy link
Member

@khanhtc1202 khanhtc1202 Jun 7, 2022

Choose a reason for hiding this comment

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

was it a miss or did we really think about allowing the remote valueFiles? I feel a bit unsafe to allow remote file value, wdyt?

Copy link
Contributor Author

@Szarny Szarny Jun 7, 2022

Choose a reason for hiding this comment

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

Since our concern here is the unauthorized rendering of unrelated sensitive information on the host on which Piped is running, remote files are outside the scope of this PR's concern, I think.

However, there may be such a case: SSRF, i.e., when a server accessible only from a host running Piped holds the confidential values file and attackers tries to render it (e.g. valueFile: https://private-server-that-can-be-accessible-only-from-piped-host.com/values.yaml) illegally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To prevent this, it may be necessary to specify an allowlist of URLs from which the values file can be read.
However, I think that allowing reachable HTTP(S) endpoints is an acceptable risk under the current circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This concept follows the advisory of GHSA-63qx-x74g-jcr7.

Copy link
Member

Choose a reason for hiding this comment

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

I understand that this is out of context on this PR 👍 My concern is currently, do we allow the remote valueFiles that way? and if it's yes, then the docs we updated may need to be updated as well.

Only files stored under the application directory are allowed.

Copy link
Member

Choose a reason for hiding this comment

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

okay, lets go with that option 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated it 👍

Copy link
Member

Choose a reason for hiding this comment

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

@Szarny
Sorry, I didn't know that ability.
Please let me confirm, will Helm automatically fetches the remote value files to apply when it was specified with HTTP scheme?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nghialv Yes, please see this pr: helm/helm#2769

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for teaching me. Didn't know about that before. 👍

khanhtc1202
khanhtc1202 previously approved these changes Jun 7, 2022
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Nice work 🙌

}

// absAppDir is a path where ".pipecd.yaml" is located.
absAppDir, err := filepath.Abs(appDir)
Copy link
Member

Choose a reason for hiding this comment

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

appDir passed to this function is an absolute path so I think we don't need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed absAppDir with this commit: 3ac6d69

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@khanhtc1202 Could you confirm the above changes? (it needs to approve again before merging)

Copy link
Member

@nghialv nghialv left a comment

Choose a reason for hiding this comment

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

Great improvement. Thank you.

@Szarny Szarny requested a review from khanhtc1202 June 7, 2022 09:58
@Szarny Szarny enabled auto-merge (squash) June 7, 2022 10:01
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Go 🚀

@Szarny Szarny merged commit 7bb5ca1 into pipe-cd:master Jun 7, 2022
@github-actions github-actions bot mentioned this pull request Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential directory traversal vuln due to Helm values file referencing outside of repo root
4 participants