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

@@ -31,7 +31,7 @@ def item(locked: bool, secret: bytes = b"t0ken") -> MagicMock:
class TestSecretServiceToken(unittest.TestCase):
def _token(self, module: types.ModuleType) -> tuple[str | None, str | None]:
with patch.dict(sys.modules, {"secretstorage": module}):
return tree.secret_service_token()
return tree._forge_access()
def test_a_locked_item_is_never_unlocked(self) -> None:
locked = item(True)
@@ -4,9 +4,8 @@ import json
import os
import shutil
import tempfile
import unittest
import unittest.mock
from types import SimpleNamespace
from unittest import mock
from pkgmgr.actions.code_scanning import (
CodeScanningError,
@@ -52,11 +51,13 @@ class TestDownloadCodeScanning(unittest.TestCase):
def test_writes_alerts_summary_and_analyses(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
with (
mock.patch(
unittest.mock.patch(
"pkgmgr.actions.code_scanning.shutil.which",
return_value="/usr/bin/gh",
),
mock.patch("pkgmgr.actions.code_scanning._gh", side_effect=_fake_gh),
unittest.mock.patch(
"pkgmgr.actions.code_scanning._gh", side_effect=_fake_gh
),
):
result = download_code_scanning(output_dir=tmp)
@@ -74,10 +75,12 @@ class TestDownloadCodeScanning(unittest.TestCase):
def test_default_output_dir_uses_repo_name(self) -> None:
with (
mock.patch(
unittest.mock.patch(
"pkgmgr.actions.code_scanning.shutil.which", return_value="/usr/bin/gh"
),
mock.patch("pkgmgr.actions.code_scanning._gh", side_effect=_fake_gh),
unittest.mock.patch(
"pkgmgr.actions.code_scanning._gh", side_effect=_fake_gh
),
):
result = download_code_scanning()
self.addCleanup(shutil.rmtree, "/tmp/pkgmgr-cs-test", ignore_errors=True)
@@ -88,7 +91,9 @@ class TestDownloadCodeScanning(unittest.TestCase):
def test_errors_when_gh_missing(self) -> None:
with (
mock.patch("pkgmgr.actions.code_scanning.shutil.which", return_value=None),
unittest.mock.patch(
"pkgmgr.actions.code_scanning.shutil.which", return_value=None
),
self.assertRaises(CodeScanningError),
):
download_code_scanning(output_dir="/tmp/should-not-be-created")
@@ -26,11 +26,6 @@ class TestMakefileInstaller(unittest.TestCase):
)
self.installer = MakefileInstaller()
# @patch("os.path.exists", return_value=True)
# def test_supports_true_when_makefile_exists(self, mock_exists):
# self.assertTrue(self.installer.supports(self.ctx))
# mock_exists.assert_called_with(os.path.join(self.ctx.repo_dir, "Makefile"))
@patch("os.path.exists", return_value=False)
def test_supports_false_when_makefile_missing(self, mock_exists):
self.assertFalse(self.installer.supports(self.ctx))
@@ -1,7 +1,6 @@
from __future__ import annotations
import unittest
from unittest import mock
import unittest.mock
from pkgmgr.actions.release.files.editor import _open_editor_for_changelog
@@ -16,7 +15,7 @@ class TestOpenEditorForChangelog(unittest.TestCase):
seen["text"] = handle.read()
return 0
with mock.patch(
with unittest.mock.patch(
"pkgmgr.actions.release.files.editor.subprocess.call", side_effect=record
):
_open_editor_for_changelog(**kwargs)
@@ -44,7 +43,7 @@ class TestOpenEditorForChangelog(unittest.TestCase):
seen["text"] = handle.read()
return 0
with mock.patch(
with unittest.mock.patch(
"pkgmgr.actions.release.files.editor.subprocess.call", side_effect=rewrite
):
kept = _open_editor_for_changelog(
+6 -7
View File
@@ -19,10 +19,9 @@ import os
import sys
import tempfile
import textwrap
import unittest
import unittest.mock
from contextlib import redirect_stdout
from typing import Any
from unittest import mock
from pkgmgr import cli
@@ -71,7 +70,7 @@ class TestCliVersion(unittest.TestCase):
}
# Patch load_config so cli.main() does not read real config files
self._patch_load_config = mock.patch(
self._patch_load_config = unittest.mock.patch(
"pkgmgr.cli.load_config", return_value=_fake_config()
)
self.mock_load_config = self._patch_load_config.start()
@@ -79,7 +78,7 @@ class TestCliVersion(unittest.TestCase):
# Patch the "current directory" selection used by dispatch_command().
# This matches the new behaviour: without explicit identifiers,
# version uses _select_repo_for_current_directory(ctx).
self._patch_select_repo_for_current_directory = mock.patch(
self._patch_select_repo_for_current_directory = unittest.mock.patch(
"pkgmgr.cli.dispatch._select_repo_for_current_directory",
return_value=[self._fake_repo],
)
@@ -165,7 +164,7 @@ class TestCliVersion(unittest.TestCase):
self._write_pyproject("1.2.3")
# Arrange: mock git tags used by handle_version
with mock.patch(
with unittest.mock.patch(
"pkgmgr.cli.commands.version.get_tags",
return_value=["v1.2.0", "v1.2.3", "v1.0.0"],
):
@@ -197,7 +196,7 @@ class TestCliVersion(unittest.TestCase):
self._write_pyproject("1.2.4")
# Arrange: mock git tags (latest is 1.2.3)
with mock.patch(
with unittest.mock.patch(
"pkgmgr.cli.commands.version.get_tags",
return_value=["v1.2.3"],
):
@@ -225,7 +224,7 @@ class TestCliVersion(unittest.TestCase):
self._write_pyproject("0.0.1")
# Arrange: no tags returned
with mock.patch(
with unittest.mock.patch(
"pkgmgr.cli.commands.version.get_tags",
return_value=[],
):
+1 -1
View File
@@ -79,7 +79,7 @@ class TestCreateInk(unittest.TestCase):
command_path = os.path.join(repo_dir, "main.sh")
with open(command_path, "w", encoding="utf-8") as f:
f.write("#!/bin/sh\necho mytool\n")
os.chmod(command_path, 0o755)
os.chmod(command_path, 0o700)
repo = {
"command": command_path,
+1 -1
View File
@@ -149,7 +149,7 @@ class TestGitRun(unittest.TestCase):
self.assertEqual(self._kept(env), ["GIT_CEILING_DIRECTORIES"])
self.assertIsNone(env.get("GIT_CONFIG_NOSYSTEM"))
self.assertEqual(env.get("HOME"), home)
self.assertFalse("XDG_CONFIG_HOME" in env)
self.assertNotIn("XDG_CONFIG_HOME", env)
def test_failure_raises_giterror_with_details(self) -> None:
# Build a CalledProcessError with stdout/stderr populated