Skip to content

[Security] Mitigate the risk of path traversal attacks through a request validator #423

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

Merged

Conversation

gmarciani
Copy link
Collaborator

Description

Mitigate the risk of path traversal attacks by adding a request validator that rejects requests containing a 'path' argument matching the unsafe path traversal pattern.

This mitigation, together with #422, provides a full mitigation of the path traversal attack.

How Has This Been Tested?

  1. Validator is covered by unit tests
  2. PCUI is working as expected: login/logout, list clusters, create cluster, delete cluster, list images
  3. The legit proxy request (the same form used by PCUI frontend) succeeds, example:
    • https://[PCUI_URL]/pcui/api?path=/v3/images/official
  4. Path traversal gets rejected, regardless it points to the legitimate or illegitimate stage. Examples:

when a path traversal is detected, now the request fails with the error:

{"code":400,"message":"Input validation failed for /api","validation_errors":{"path":["Invalid value."]}}

References

PR Quality Checklist

  • I added tests to new or existing code
  • I removed hardcoded strings and used react-i18next library (useTranslation hook and/or Trans component), see an example here
  • I made sure no sensitive info gets logged at any time in the codebase (see here) (e.g. no user info or details, no stacktraces, etc.)
  • I made sure that any GitHub issue solved by this PR is correctly linked
  • I checked that infrastructure/update_infrastructure.sh runs without any error
  • I checked that npm run build builds without any error
  • I checked that clusters are listed correctly
  • I checked that a new cluster can be created (config is produced and dry run passes)
  • I checked that login and logout work as expected

In order to increase the likelihood of your contribution being accepted, please make sure you have read both the Contributing Guidelines and the Project Guidelines

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…quest validator that rejects requests containing a 'path' argument matching the unsafe path traversal pattern.
@gmarciani gmarciani force-pushed the wip/mgiacomo/2025060/path-traversal-0605-1 branch from 7bb62d6 to cb8f877 Compare June 5, 2025 21:03
@himani2411
Copy link
Contributor

Can we have more descriptive error message as the below message might look like /api is Invalid instead of the PATH /../Stage/v3/images/official

{"code":400,"message":"Input validation failed for /api","validation_errors":{"path":["Invalid value."]}}

@gmarciani
Copy link
Collaborator Author

@himani2411 Input validation failed for ${api_resource} this is the current messaging PCUI returns for whatever validation error. It is defined here:

raise ValidationError(f'Input validation failed for {request.path}', data=errors)

I agree it may be misleading. What about changing it to Input validation failed for requested resource ${api_resource}?

…validation errors.
@himani2411
Copy link
Contributor

@himani2411 Input validation failed for ${api_resource} this is the current messaging PCUI returns for whatever validation error. It is defined here:

raise ValidationError(f'Input validation failed for {request.path}', data=errors)

I agree it may be misleading. What about changing it to Input validation failed for requested resource ${api_resource}?

Agreed on messaging

@gmarciani gmarciani merged commit c43409d into aws:main Jun 30, 2025
2 checks passed
@gmarciani gmarciani deleted the wip/mgiacomo/2025060/path-traversal-0605-1 branch June 30, 2025 17:03
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.

None yet

2 participants