Skip to content

fix: prevent version bump script from following symlinks - #2789

Open
Rana Singh (ranadeepsingh) wants to merge 1 commit into
microsoft:masterfrom
ranadeepsingh:fix/prevent-version-bump-symlink-writes
Open

Rana Singh (ranadeepsingh) wants to merge 1 commit into
microsoft:masterfrom
ranadeepsingh:fix/prevent-version-bump-symlink-writes

Conversation

@ranadeepsingh

@ranadeepsingh Rana Singh (ranadeepsingh) commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Related Issues/PRs

None.

What changes are proposed in this pull request?

This hardens scripts/bump-version.py so it cannot follow symlinks outside the repository selected with --repo-root.

The script now:

  • skips symlinks while discovering files
  • refuses resolved paths outside the selected repository root before writing
  • opens rooted files with directory file descriptors and no-follow flags on supported platforms
  • rejects symlinked final paths, parent symlinks, directories, hard links, and unsupported platforms
  • skips symlinks and out-of-root paths during verification and broad sweeps
  • warns when it skips a symlink

This is a focused maintenance-tool hardening change. It does not change normal in-repository version replacement behavior.

How is this patch tested?

  • I have written tests and confirmed the proposed fix works.
  • python3 -m pytest -q scripts/test_bump_version.py -k 'not TestSnapshotRegression': 215 passed, 4 deselected.
  • Targeted symlink escape reproduction: passed. The outside file remained unchanged and the script warned that it skipped the symlink.
  • Added regression coverage for existing symlinks, parent symlinks, directory targets, hard links, symlink swaps, and unsupported platforms.
  • git diff --check: passed.
  • Black formatting API: passed.

Does this PR change any dependencies?

  • No. You can skip this section.
  • Yes. Make sure the dependencies are resolved correctly, and list changes here.

Does this PR add a new feature? If so, have you added samples on website?

  • No. You can skip this section.
  • Yes. Make sure you have added samples following below steps.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 10:13
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions

Copy link
Copy Markdown

Hey Rana Singh (@ranadeepsingh) 👋!
Thank you so much for contributing to our repository 🙌.
Someone from SynapseML Team will be reviewing this pull request soon.

We use semantic commit messages to streamline the release process.
Before your pull request can be merged, you should make sure your first commit and PR title start with a semantic prefix.
This helps us to create release messages and credit you for your hard work!

Examples of commit messages with semantic prefixes:

  • fix: Fix LightGBM crashes with empty partitions
  • feat: Make HTTP on Spark back-offs configurable
  • docs: Update Spark Serving usage
  • build: Add codecov support
  • perf: improve LightGBM memory usage
  • refactor: make python code generation rely on classes
  • style: Remove nulls from CNTKModel
  • test: Add test coverage for CNTKModel

To test your commit locally, please follow our guild on building from source.
Check out the developer guide for additional guidance on testing your change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Concurrent path replacement can bypass the checks and redirect a write outside the selected repository.

1 open issue
What changed in this PR

This PR hardens the version-bump maintenance script against symlinks that point outside the selected repository.

Changes:

  • Skips symlinked files during discovery and warns when they are encountered.
  • Adds containment checks before writing and excludes unsafe paths from broad verification sweeps.
  • Adds a regression test confirming that an existing external symlink target remains unchanged.
File Description
scripts/​test_bump_version.py Adds coverage for an external symlink target.
scripts/​bump-version.py Adds symlink and repository-containment checks.

Review effort: Balanced

Comment thread scripts/bump-version.py Outdated
## Summary
Keep the version bump script inside the repository selected with
`--repo-root`. Skip symlinks, reject unsafe paths, and use rooted
directory file descriptors for race-safe reads and writes.

## Prompting Intent
The engineer asked to implement the confirmed hardening case from the
private security review, add focused regression coverage, validate it,
and prepare the public pull request. The change should be small and
should not describe private report details in public Git or PR text.

## Linked Sources
- Private security triage: reviewed in the SynapseML advisory thread;
  detailed report information deliberately omitted from public history.
- Repository guidance: AGENTS.md and the master branch context.
- Existing test suite: scripts/test_bump_version.py.

## Rationale
Resolving and checking each candidate path closes the concrete symlink
escape while preserving normal in-repository version replacement. The
script now skips symlinks during discovery and post-verification, and
opens files by their relative path through the repository root. It also
rejects symlinked or non-regular final paths and fails closed on
platforms without the directory file descriptor and no-follow support
needed for a race-safe open. The change is narrower than changing CLI
behavior or adding a global scanner suppression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: af31ef86-1171-422a-abeb-c63e597a01a2
Copilot AI balanced review requested due to automatic review settings October 23, 2026 11:20
@ranadeepsingh
Rana Singh (ranadeepsingh) force-pushed the fix/prevent-version-bump-symlink-writes branch from 2ed1380 to a9bb6ec Compare October 23, 2026 11:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Root-directory swaps can still permit outside writes, and unsupported platforms can report success without updating files.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread scripts/bump-version.py


def _safe_open_relative(root, rel, flags, mode=0):
root = root.resolve(strict=True)
Comment thread scripts/bump-version.py
FileNotFoundError,
UnicodeDecodeError,
PermissionError,
UnsafeRootedPath,

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants