From 8050f0734001707ab01b41dc9f366b942ed9fa67 Mon Sep 17 00:00:00 2001 From: "hf-security-analysis[bot]" <265538906+hf-security-analysis[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 11:18:52 +0000 Subject: [PATCH] fix(ci): harden workflow design flagged on #14789 --- .github/workflows/issue_labeler.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/issue_labeler.yml b/.github/workflows/issue_labeler.yml index 2fd7faea1693..471164c2eb36 100644 --- a/.github/workflows/issue_labeler.yml +++ b/.github/workflows/issue_labeler.yml @@ -33,6 +33,28 @@ jobs: ISSUE_NUMBER: ${{ github.event.issue.number }} LABELS: ${{ steps.get-labels.outputs.labels }} run: | - for label in $(echo "$LABELS" | python -c "import json,sys; print('\n'.join(json.load(sys.stdin)))"); do - gh issue edit "$ISSUE_NUMBER" --add-label "$label" + # LLM output is untrusted: only apply labels that already exist in the repo, + # never apply security-sensitive labels, and cap the number applied. + EXISTING_LABELS=$(gh label list --repo "$GITHUB_REPOSITORY" --limit 1000 --json name --jq '.[].name') + echo "$LABELS" | EXISTING_LABELS="$EXISTING_LABELS" python -c " + import json, os, re, sys + existing = set(l.strip() for l in os.environ.get('EXISTING_LABELS', '').splitlines() if l.strip()) + blocked = re.compile(r'(safe|ok|ready)[-_ ]?(to|for)[-_ ]?(test|merge|deploy|run)|approved|lgtm|security|deploy|release|priority|critical|\\bci\\b|run[-_ ]?ci|maintainer|trusted', re.I) + try: + data = json.load(sys.stdin) + except Exception: + data = [] + if not isinstance(data, list): + data = [] + out = [] + for l in data: + if isinstance(l, str) and l in existing and not blocked.search(l) and l not in out: + out.append(l) + if len(out) >= 3: + break + print('\n'.join(out)) + " | while IFS= read -r label; do + if [ -n "$label" ]; then + gh issue edit "$ISSUE_NUMBER" --add-label "$label" + fi done