Fix: Add path sanitization for api_environment to prevent path traversal#63691
Open
K1nakoo wants to merge 5 commits intoapache:mainfrom
Open
Fix: Add path sanitization for api_environment to prevent path traversal#63691K1nakoo wants to merge 5 commits intoapache:mainfrom
K1nakoo wants to merge 5 commits intoapache:mainfrom
Conversation
…t to prevent path traversalnvironment name Validate the API environment name to allow only alphanumeric characters, dashes, and underscores.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
Contributor
|
Congratulations on your first PR @kianelbo !! |
Author
|
What? who is that haha . But thank you so much for the review and the warm welcome, @Srabasti! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR introduces a strict regex validation for the
api_environmentvariable (populated via CLI arguments orAIRFLOW_CLI_ENVIRONMENT) within theCredentialsclass ofairflowctl.Why is this needed?
Currently, the environment name is directly passed to
os.path.join(default_config_dir, f"{self.api_environment}.json")without any sanitization.While
airflowctlis a client tool, it is frequently executed in automated CI/CD pipelines where the environment variable might be populated dynamically (e.g., from a Git branch name or GitHub Actions runner). If an untrusted input containing directory traversal sequences (like../../../tmp/evil) is passed, it could unintentionally write.jsonfiles outside the target configuration directory, leading to potential CI pipeline configuration overrides.This patch enforces a Defense-in-Depth approach, ensuring that only valid, safe alphanumeric names (including dashes, periods, and underscores) are processed, completely mitigating the risk of path traversal.
Testing done
production,dev.env-1) work as expected.../evil) correctly raises aValueErrorand halts execution before any file system operations occur.Was generative AI tooling used to co-author this PR?
Generated-by: Gemini following the guidelines