Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/scheduled-security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ jobs:
with:
persist-credentials: false
- name: Initialize CodeQL
uses: github/codeql-action/init@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # v4.37.0
uses: github/codeql-action/init@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- name: Perform CodeQL Analysis
continue-on-error: true
uses: github/codeql-action/analyze@99df26d4f13ea111d4ec1a7dddef6063f76b97e9 # v4.37.0
uses: github/codeql-action/analyze@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
with:
category: "/language:${{ matrix.language }}-scheduled"

Expand Down
24 changes: 20 additions & 4 deletions scripts/ci/pr_review_merge_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import subprocess
import sys
import time
import unicodedata
from collections.abc import Sequence
from dataclasses import dataclass
from datetime import datetime, timezone
Expand Down Expand Up @@ -126,7 +127,7 @@
RUNNING_CHECK_STATES = {"PENDING", "EXPECTED", "QUEUED", "IN_PROGRESS", "WAITING", "REQUESTED"}
FAILED_CHECK_CONCLUSIONS = {"FAILURE", "ERROR", "CANCELLED", "TIMED_OUT", "STARTUP_FAILURE"}
ACTION_REQUIRED_CONCLUSIONS = {"ACTION_REQUIRED"}
GIT_REF_RE = re.compile(r"^(?!-)[A-Za-z0-9._/-]+$")
GIT_REF_ASCII_SAFE_CHARS = frozenset("._/-")
GIT_SHA_RE = re.compile(r"^[0-9a-fA-F]{40}$")
GITHUB_REPOSITORY_RE = re.compile(r"^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$")
REVIEW_BODY_HEAD_SHA_RE = re.compile(r"Head SHA:\s*`([0-9a-fA-F]{40})`")
Expand Down Expand Up @@ -529,20 +530,35 @@ def split_repo(repo: str) -> tuple[str, str]:


def validate_git_ref(ref: str) -> str:
"""Return a conservative Git ref name for gh workflow dispatch fields."""
"""Return a conservative Unicode-capable Git ref for structured argv/JSON fields."""
has_unsafe_character = isinstance(ref, str) and any(
(
character.isascii()
and not (character.isalnum() or character in GIT_REF_ASCII_SAFE_CHARS)
)
or (
not character.isascii()
and unicodedata.category(character)[0] in {"C", "Z"}
)
for character in ref
)
if (
not isinstance(ref, str)
or not ref
or not GIT_REF_RE.fullmatch(ref)
or has_unsafe_character
or ref == "HEAD"
or ref.startswith("-")
or ref.startswith("/")
or ref.endswith(("/", "."))
or "@{" in ref
or ".." in ref
or "//" in ref
):
raise ValueError(f"invalid git ref: {ref!r}")
if any(part == "." or part.startswith(".") for part in ref.split("/")):
if any(
part == "." or part.startswith(".") or part.endswith(".lock")
for part in ref.split("/")
):
raise ValueError(f"invalid git ref: {ref!r}")
return ref

Expand Down
20 changes: 17 additions & 3 deletions tests/test_pr_review_merge_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ def test_run_split_repo_and_graphql(monkeypatch):
with pytest.raises(ValueError):
sched.split_repo("/repo")

assert sched.validate_git_ref("feature/safe.branch-1") == "feature/safe.branch-1"
for valid_ref in (
"feature/safe.branch-1",
"๐ŸŽจ-palette-ux-improvement-13325911538352561627",
"๊ธฐ๋Šฅ/๋‹ฌ๋ ฅ-๊ฐœ์„ ",
):
assert sched.validate_git_ref(valid_ref) == valid_ref
for bad_ref in (
"",
"-bad",
Expand All @@ -172,8 +177,11 @@ def test_run_split_repo_and_graphql(monkeypatch):
"feature/./main",
"feature//main",
"feature/main.",
"feature/main.lock",
"feature/@{upstream}",
"feat;echo pwned",
"feature/\u00a0hidden",
"feature/\u200bhidden",
):
with pytest.raises(ValueError):
sched.validate_git_ref(bad_ref)
Expand Down Expand Up @@ -1891,6 +1899,7 @@ def test_missing_evidence_dispatch_uses_central_required_workflow_repository(mon
calls = []
head_sha = "a" * 40
base_sha = "b" * 40
head_ref = "๐ŸŽจ-palette-ux-improvement-13325911538352561627"

def fake_run_with_env(args, *, stdin=None, env=None):
calls.append((args, stdin, None if env is None else env.get("GH_TOKEN")))
Expand All @@ -1905,7 +1914,12 @@ def fake_run_with_env(args, *, stdin=None, env=None):
monkeypatch.setenv("SCHEDULER_REQUIRED_WORKFLOW_REPOSITORY", "ContextualWisdomLab/.github")
monkeypatch.setenv("SCHEDULER_REQUIRED_WORKFLOW_REF", "main")

pr = make_pr(baseRefName="develop", baseRefOid=base_sha, headRefOid=head_sha)
pr = make_pr(
baseRefName="develop",
baseRefOid=base_sha,
headRefName=head_ref,
headRefOid=head_sha,
)
sched.dispatch_strix_evidence("owner/repo", "Strix Security Scan", pr, dry_run=False)
sched.dispatch_opencode_review("owner/repo", "OpenCode Review", pr, dry_run=False)

Expand Down Expand Up @@ -1950,7 +1964,7 @@ def fake_run_with_env(args, *, stdin=None, env=None):
"pr_number": 1,
"pr_base_ref": "develop",
"pr_base_sha": base_sha,
"pr_head_ref": "feature",
"pr_head_ref": head_ref,
"pr_head_sha": head_sha,
},
}
Expand Down
Loading