refactor: improve path handling in config, node steps, and build#2015
refactor: improve path handling in config, node steps, and build#2015niStee wants to merge 24 commits into
Conversation
… in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…/consolidated-codeql-fixes
…/consolidated-codeql-fixes
…/consolidated-codeql-fixes
…/consolidated-codeql-fixes
…age management logic
|
There is another one: Uncontrolled data used in path expression. let exe_path = current_exe()?; |
GideonBear
left a comment
There was a problem hiding this comment.
Not going to fully review yet. Can you explain individually for each case why it's dangerous?
….rs, and self_renamer.rs
|
Hi @GideonBear, thank you so much for the detailed review! You were right to point out that the initial commits were heavily influenced by Copilot autofixes and ended up being overly defensive. I had a fundamental misunderstanding of the threat model for a local CLI tool and of how certain standard library functions behave. I really appreciate you highlighting these issues, particularly with regard to build.rs. Thanks to your feedback, I have learnt a lot more about Cargo's environment variables and trust model. I have completely refactored the pull request (PR) to address the CodeQL alerts properly and remove the unnecessary precautions. The PR is now out of draft mode. Please let me know if you think the new approach looks good! |
What does this PR do
Improves code quality and readability by refactoring path handling across several modules to be more idiomatic.
Note: This PR originally started as an attempt to resolve CodeQL path traversal alerts using AI autofixes. After maintainer review, we determined those alerts were false positives given the threat model of a local CLI tool. The overly defensive security checks and suppressions were removed, and the PR was repurposed to focus purely on structural code health.
Key Changes:
src/config.rs: Flattened the directory traversal logic to reduce unnecessary rightward drift and cachedentry.path()to avoid redundant calls inside the loop.src/steps/node.rs: Refactored to use more idiomaticPathBufhandling.build.rs: Cleaned up theOUT_DIRpath parsing logic to use safe, ownedPathBufrepresentations.Standards checklist
CONTRIBUTING.mdAI involvement
Initial overly defensive fixes were generated by GitHub Copilot. The final implementation was refined manually based on maintainer feedback to focus on standard Rust refactoring rather than security suppressions.