Skip to content

Commit a61a7da

Browse files
committed
fix: use safe default mode for shared text writes
1 parent d7dda01 commit a61a7da

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/specify_cli/shared_infra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _write_shared_bytes(
163163
dest: Path,
164164
content: bytes,
165165
*,
166-
mode: int = 0o666,
166+
mode: int = 0o644,
167167
) -> None:
168168
_ensure_safe_shared_destination(project_path, dest)
169169
fd, temp_name = tempfile.mkstemp(prefix=f".{dest.name}.", dir=dest.parent)

tests/integrations/test_cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,32 @@ def test_shared_infra_install_supports_nested_script_sources(self, tmp_path):
468468
nested_dest = project / ".specify" / "scripts" / "bash" / "nested" / "deep.sh"
469469
assert nested_dest.read_text(encoding="utf-8") == "# nested\n"
470470

471+
@pytest.mark.skipif(os.name == "nt", reason="POSIX mode bits are not stable on Windows")
472+
def test_shared_template_writes_are_not_world_writable(self, tmp_path):
473+
"""Shared template writes use a safe default mode instead of chmod 666."""
474+
from specify_cli.shared_infra import install_shared_infra
475+
476+
project = tmp_path / "template-mode-test"
477+
project.mkdir()
478+
479+
core_pack = tmp_path / "core-pack"
480+
templates_src = core_pack / "templates"
481+
templates_src.mkdir(parents=True)
482+
(templates_src / "plan-template.md").write_text("# plan\n", encoding="utf-8")
483+
484+
install_shared_infra(
485+
project,
486+
"sh",
487+
version="test",
488+
core_pack=core_pack,
489+
repo_root=tmp_path / "unused",
490+
console=_NoopConsole(),
491+
force=True,
492+
)
493+
494+
written = project / ".specify" / "templates" / "plan-template.md"
495+
assert written.stat().st_mode & 0o777 == 0o644
496+
471497
def test_shared_infra_no_warning_when_forced(self, tmp_path, capsys):
472498
"""No skip warning when force=True (all files overwritten)."""
473499
from specify_cli import _install_shared_infra

0 commit comments

Comments
 (0)