fix(security): close the 32 open CodeQL alerts

Critical #60/#61 untrusted checkout: publish-containers.yml prepare runs for workflow_run only when the triggering run succeeded, was a push and came from this repository; build and merge need prepare, so the guard covers both checkouts. Mark stable commit triggers only on push of v* tags, schedule and workflow_dispatch are unchanged. Medium #55/#56: update-flake-lock.yml pins nix-installer-action v23 and update-flake-lock v29 to commit SHAs. High: secret_service_token returns only the token and raises SecretServiceUnavailable with the same reasons, _forge_access builds the token/reason pair (#62); jinja2 select_autoescape for html/htm/xml only, scaffolding output byte-identical (#29); chmod 0o755 to 0o700 for owner-run scripts in ink.py and 7 test sites; exact URL equality in a mirror probe test. Error #33: raise unittest.SkipTest from exc. Notes: empty-except to contextlib.suppress, one import form per module, unused variable, commented-out code, assertNotIn.

| 🌿 Branch | 📊 Diff stat | 🎯 Fix | 💥 Break | 💸 Tokens | ⏱️ Velocity | 🛡️ Security | 🏆 Score | Gate |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| fix/codeql-alerts | 28 files +92/-81 | 90 % | 3 % | – | – | 100 % | 87 | ✅ 90/5, tokens and velocity <= 100, security 100 % |

Evidence: tests/unit + tests/integration 880 passed, 574 subtests; 2 test_publish_integration failures are identical on a clone without these changes (global tag.gpgsign, sandbox blocks gpg). ruff and actionlint clean, MEDUSA 100 % critical 0 (1 accepted keyword false positive). Operator choice 7589a6f1 (swarm), operator review dcc2f461.
Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-30 20:19:21 +00:00
1 parent f529139db5
commit 0f6583ca48
28 files changed
+92 -81

No files matched your search

@@ -116,7 +116,7 @@ class TestBranchCleanupLocal(unittest.TestCase):
docker = os.path.join(self.bin, "docker")
with open(docker, "w", encoding="utf-8") as fh:
fh.write(FAILING_DOCKER.format(python=sys.executable))
os.chmod(docker, 0o755)
os.chmod(docker, 0o700)
self.docker_log = os.path.join(self.root, "docker.log")
def tearDown(self) -> None:
@@ -159,7 +159,7 @@ class TestBranchCleanupLocal(unittest.TestCase):
patch.object(gc_forge, "TokenResolver") as resolver,
patch.object(gc_forge, "HttpClient") as http,
patch.object(
tree, "secret_service_token", return_value=(None, "test")
tree, "_forge_access", return_value=(None, "test")
) as secret,
):
resolver.return_value.get_token.side_effect = NoCredentialsError("none")
@@ -1688,7 +1688,7 @@ class TestBranchCleanupLocal(unittest.TestCase):
path = os.path.join(hooks, name)
with open(path, "w", encoding="utf-8") as fh:
fh.write(MARKING_HOOK.format(marker=marker))
os.chmod(path, 0o755)
os.chmod(path, 0o700)
run = self._cleanup("local", apply=True)
+1 -1
View File
@@ -534,7 +534,7 @@ class TestBranchGc(GcFixture, unittest.TestCase):
hook = os.path.join(self.repo, ".git", "hooks", "reference-transaction")
with open(hook, "w") as fh:
fh.write(f"#!/bin/sh\ntouch {marker}\n")
os.chmod(hook, 0o755)
os.chmod(hook, 0o700)
plan = self._plan(host_ns=True, cwds={})
item = self._items(plan)["merged"]
+4 -4
View File
@@ -110,7 +110,7 @@ class TestBranchTree(unittest.TestCase):
patch.object(gc, "_process_cwds", return_value={}),
patch.object(
tree,
"secret_service_token",
"_forge_access",
return_value=(None, "Secret Service locked"),
),
]
@@ -389,7 +389,7 @@ class TestBranchTree(unittest.TestCase):
open_heads={},
)
with (
patch.object(tree, "secret_service_token", return_value=("t0ken", None)),
patch.object(tree, "_forge_access", return_value=("t0ken", None)),
patch.object(tree, "facts_with_token", return_value=facts) as live,
):
first = self._by_branch(self._entry())
@@ -408,7 +408,7 @@ class TestBranchTree(unittest.TestCase):
(False, "Secret Service locked"),
)
self.assertEqual(data["repos"][0]["forge"], "cached")
with patch.object(tree, "secret_service_token", return_value=("t0ken", None)):
with patch.object(tree, "_forge_access", return_value=("t0ken", None)):
self.assertTrue(json.loads(self._tree())["delete_ready"])
def test_an_unwritable_cache_keeps_the_scan_and_names_it(self) -> None:
@@ -417,7 +417,7 @@ class TestBranchTree(unittest.TestCase):
self._write(self.root, "cache-is-a-file", "")
with (
patch.dict(os.environ, {"XDG_CACHE_HOME": blocker}),
patch.object(tree, "secret_service_token", return_value=("t0ken", None)),
patch.object(tree, "_forge_access", return_value=("t0ken", None)),
patch.object(tree, "facts_with_token", return_value=ForgeFacts()),
):
entry = self._entry()
+1 -1
View File
@@ -22,7 +22,7 @@ class TestBranchTreeFlow(GcFixture, unittest.TestCase):
patch.object(gc, "host_pid_namespace", return_value=True),
patch.object(gc, "list_compose_containers", return_value=[]),
patch.object(gc, "_process_cwds", return_value={}),
patch.object(tree, "secret_service_token", return_value=(None, "locked")),
patch.object(tree, "_forge_access", return_value=(None, "locked")),
):
patcher.start()
self.addCleanup(patcher.stop)
@@ -164,7 +164,7 @@ class TestInstalledVersionDegradation(unittest.TestCase):
self.assertIsNone(get_installed_python_version("kpmx"))
def test_non_json_nix_profile_output_falls_back_to_text_mode(self) -> None:
import pkgmgr.core.version.installed as mod
from pkgmgr.core.version import installed as mod
with (
patch.object(mod.shutil, "which", return_value="/usr/bin/nix"),
@@ -173,7 +173,7 @@ class TestInstalledVersionDegradation(unittest.TestCase):
self.assertIsNone(mod.get_installed_nix_profile_version("pkgmgr"))
def test_json_list_instead_of_object_is_tolerated(self) -> None:
import pkgmgr.core.version.installed as mod
from pkgmgr.core.version import installed as mod
# Valid JSON, wrong shape: data.get() raises AttributeError on a list.
with (
@@ -566,7 +566,7 @@ class TestReleaseFileWriteDegradation(unittest.TestCase):
self.assertIn("Could not read spec file for changelog update", buf.getvalue())
def test_unwritable_spec_changelog_is_reported(self) -> None:
import pkgmgr.actions.release.files.rpm_changelog as mod
from pkgmgr.actions.release.files import rpm_changelog as mod
path = _write(
os.path.join(self.dir, "pkg.spec"),
+1 -2
View File
@@ -4,7 +4,6 @@ import unittest
from unittest.mock import patch
import pkgmgr.actions.install as install_module
from pkgmgr.actions.install import install_repos
from pkgmgr.actions.install.installers.base import BaseInstaller
@@ -141,7 +140,7 @@ class TestInstallReposIntegration(unittest.TestCase):
old_installers = install_module.INSTALLERS
install_module.INSTALLERS = [DummyInstaller()]
try:
install_repos(
install_module.install_repos(
selected_repos=selected_repos,
repositories_base_dir=tmp_base,
bin_dir=tmp_bin,
@@ -129,7 +129,7 @@ class TestIntegrationMirrorProbeDetailAndProvision(unittest.TestCase):
]
def probe_side_effect(url: str, cwd: str = "."):
if "github.com" in url:
if url == "git@github.com:alice/repo.git":
# show "empty repo reachable" note; setup_cmd prints [OK] and does not print reason for ok
return (
True,
@@ -180,7 +180,7 @@ class TestIntegrationMirrorProbeDetailAndProvision(unittest.TestCase):
]
def probe_side_effect(url: str, cwd: str = "."):
if "github.com" in url:
if url == "git@github.com:alice/repo.git":
return True, ""
return False, "(exit 128) fatal: Could not read from remote repository."
+2 -4
View File
@@ -6,7 +6,7 @@ import shutil
import subprocess
import tempfile
import unittest
from contextlib import redirect_stdout
from contextlib import redirect_stdout, suppress
from pathlib import Path
from unittest.mock import patch
@@ -339,10 +339,8 @@ class TestPushMirrorLeases(unittest.TestCase):
hooks_fire = marker.exists()
marker.unlink(missing_ok=True)
try:
with suppress(PushRefusedError):
self._push()
except PushRefusedError:
pass
self.assertFalse(marker.exists(), f"config hooks fire on commit: {hooks_fire}")
@@ -14,7 +14,6 @@ from collections.abc import Sequence
from unittest.mock import patch
import pkgmgr.actions.install as install_mod
from pkgmgr.actions.install import install_repos
from pkgmgr.actions.install.installers.makefile import MakefileInstaller
from pkgmgr.actions.install.installers.nix import NixFlakeInstaller
from pkgmgr.actions.install.installers.os_packages.arch_pkgbuild import (
@@ -89,7 +88,7 @@ class TestRecursiveCapabilitiesIntegration(unittest.TestCase):
),
patch.object(install_mod, "clone_repos"),
):
install_repos(
install_mod.install_repos(
selected_repos=selected_repos,
repositories_base_dir=self.tmp_root,
bin_dir=self.bin_dir,
@@ -14,7 +14,7 @@ class TestIntegrationReposCreatePreview(unittest.TestCase):
try:
repos_mod = importlib.import_module("pkgmgr.cli.commands.repos")
except ImportError as exc:
self.skipTest(f"CLI module not available: {exc}")
raise unittest.SkipTest(f"CLI module not available: {exc}") from exc
handle = getattr(repos_mod, "handle_repos_command", None)
if handle is None:
+1 -1
View File
@@ -58,7 +58,7 @@ class ReviewRepoCase(unittest.TestCase):
def _trap(self, path: str, tail: str) -> str:
write(path, f"#!/bin/sh\ntouch '{self.marker}'\n{tail}\n".encode())
os.chmod(path, 0o755)
os.chmod(path, 0o700)
return path
def _assert_fires(self, *args: str) -> None:
+2 -2
View File
@@ -331,7 +331,7 @@ class TestWorktreeUp(WorktreeFixture, unittest.TestCase):
script = os.path.join(self.repo, name)
with open(script, "w") as fh:
fh.write(f"#!/bin/sh\ntouch {marker}\n")
os.chmod(script, 0o755)
os.chmod(script, 0o700)
git(self.repo, "add", name)
git(self.repo, "commit", "-m", name)
git(self.repo, "push", "origin", "main")
@@ -370,7 +370,7 @@ class TestWorktreeUp(WorktreeFixture, unittest.TestCase):
fake = os.path.join(planted, "true")
with open(fake, "w") as fh:
fh.write(f"#!/bin/sh\ntouch {marker}\n")
os.chmod(fake, 0o755)
os.chmod(fake, 0o700)
if os.getuid() == 0:
os.chown(planted, 65534, 65534)
os.chown(fake, 65534, 65534)