Skip to content

Commit a397de4

Browse files
author
kevin
authored
fix(bundles): refuse to build when bundle.yml or README.md is a symlink (github#5169)
The packager skips symlinked files, but build_bundle checked the manifest and README by following links. A symlinked bundle.yml/README.md therefore built "successfully" into a zip without them, which `bundle install` then rejected. Fail the build with a clear error instead. Fixes github#5088 Assisted-by: Grok Bot (model: unknown, autonomous) Signed-off-by: kevin9327 <[email protected]>
1 parent 80f5935 commit a397de4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎src/specify_cli/bundles/packager.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ def build_bundle(
4848
"README.md describing it."
4949
)
5050

51+
# The packager never packages symlinked files, so a symlinked manifest or
52+
# README would pass the checks above yet be left out of the artifact,
53+
# producing a zip that 'specify bundle install' rejects. Fail the build.
54+
for required in (manifest_path, bundle_dir / "README.md"):
55+
if required.is_symlink():
56+
raise BundlerError(
57+
f"'{required.name}' in '{bundle_dir}' is a symlink. The manifest "
58+
"and README.md must be regular files so they are included in "
59+
"the artifact."
60+
)
61+
5162
manifest = BundleManifest.from_file(manifest_path)
5263
report = validate_manifest(manifest)
5364
if not report.ok:

‎tests/specify_cli/bundles/test_packager.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ def test_symlinked_directory_is_not_followed(tmp_path: Path):
170170
assert not any("secret" in name for name in names)
171171

172172

173+
@pytest.mark.parametrize("name", ["bundle.yml", "README.md"])
174+
def test_build_refuses_symlinked_manifest_or_readme(tmp_path: Path, name: str):
175+
bundle = _make_bundle(tmp_path / "b")
176+
(bundle / "shared").mkdir()
177+
(bundle / name).rename(bundle / "shared" / name)
178+
try:
179+
(bundle / name).symlink_to(Path("shared") / name)
180+
except (OSError, NotImplementedError):
181+
pytest.skip("symlinks not supported on this platform")
182+
# The packager skips symlinked files, so building would otherwise succeed
183+
# and emit an artifact without the manifest or README at its root.
184+
with pytest.raises(BundlerError, match="symlink"):
185+
build_bundle(bundle, output_dir=tmp_path / "out")
186+
assert not list((tmp_path / "out").glob("*.zip"))
187+
188+
173189
def test_unsafe_bundle_id_is_rejected_before_build(tmp_path: Path):
174190
data = valid_manifest_dict()
175191
data["bundle"]["id"] = "../evil"

0 commit comments

Comments
 (0)