From 0d0e97f73ca10d1538d6da12c6fdbd409f8074e6 Mon Sep 17 00:00:00 2001 From: lelia <2418071+lelia@users.noreply.github.com> Date: Fri, 4 Dec 2026 21:22:35 -0500 Subject: [PATCH] Resolve open code scanning alerts Remove the workflow_dispatch trigger from the PR preview workflow. A dispatch runs from the default branch, so the build job ran pull request code with write access to the default branch's Actions cache. Label events run in the pull request's own cache scope and stay as the only way to publish previews. Drive the FOSSA CVSS metric lookup from a table of prop keys. CodeQL treated the literal "confidentialityImpact" lookup as secret data and flagged the JSON report written to the console; the value is a public CVSS metric. Bump the version to 2.15.11. --- .github/workflows/pr-preview.yml | 48 +++----------------------------- CHANGELOG.md | 9 ++++++ CONTRIBUTING.md | 17 +++++------ pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- socketsecurity/fossa_compat.py | 26 +++++++++-------- uv.lock | 2 +- 7 files changed, 38 insertions(+), 68 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 7b08efff..f2e86183 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -3,35 +3,14 @@ name: Publish PR Preview on: pull_request: types: [labeled] - workflow_dispatch: - inputs: - pr_number: - description: Pull request number to publish - required: true - type: string - publish_test_pypi: - description: Publish the Python package to TestPyPI - required: true - default: true - type: boolean - publish_docker: - description: Publish socketdev/cli:pr- to Docker Hub - required: true - default: false - type: boolean - sdk_preview_version: - description: Optional exact TestPyPI socketdev prerelease for the Docker image - required: false - type: string concurrency: - group: publish-pr-preview-${{ github.event.pull_request.number || github.run_id }} + group: publish-pr-preview-${{ github.event.pull_request.number }} cancel-in-progress: false jobs: context: if: >- - github.event_name == 'workflow_dispatch' || (github.event.label.name == 'publish-preview' || github.event.label.name == 'publish-docker-preview') && github.event.pull_request.head.repo.full_name == github.repository @@ -48,28 +27,15 @@ jobs: id: context uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} EVENT_PR_NUMBER: ${{ github.event.pull_request.number }} - INPUT_PR_NUMBER: ${{ inputs.pr_number }} - WORKFLOW_REF: ${{ github.ref }} with: script: | - const rawPrNumber = context.eventName === 'workflow_dispatch' - ? process.env.INPUT_PR_NUMBER - : process.env.EVENT_PR_NUMBER; + const rawPrNumber = process.env.EVENT_PR_NUMBER; if (!/^[1-9][0-9]*$/.test(rawPrNumber || '')) { core.setFailed('Pull request number must contain ASCII digits only.'); return; } - if (context.eventName === 'workflow_dispatch') { - const defaultRef = `refs/heads/${process.env.DEFAULT_BRANCH}`; - if (process.env.WORKFLOW_REF !== defaultRef) { - core.setFailed(`Run manual previews from ${defaultRef}.`); - return; - } - } - const prNumber = Number(rawPrNumber); if (!Number.isSafeInteger(prNumber)) { core.setFailed('Pull request number is outside the supported range.'); @@ -162,9 +128,7 @@ jobs: publish-package: needs: [context, build] - if: >- - github.event.label.name == 'publish-preview' || - (github.event_name == 'workflow_dispatch' && inputs.publish_test_pypi) + if: github.event.label.name == 'publish-preview' runs-on: ubuntu-latest timeout-minutes: 10 permissions: @@ -228,9 +192,7 @@ jobs: publish-docker: needs: [context, build] - if: >- - github.event.label.name == 'publish-docker-preview' || - (github.event_name == 'workflow_dispatch' && inputs.publish_docker) + if: github.event.label.name == 'publish-docker-preview' runs-on: ubuntu-latest timeout-minutes: 15 permissions: @@ -274,8 +236,6 @@ jobs: # arm64 layer builds under emulation, so expect roughly double the runtime. platforms: linux/amd64,linux/arm64 tags: socketdev/cli:pr-${{ needs.context.outputs.pr_number }} - build-args: | - SDK_PREVIEW_VERSION=${{ inputs.sdk_preview_version }} - name: Comment on pull request uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 018a314a..37d90f6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 2.15.11 + +### Security + +- Removed the manual dispatch trigger from the pull request preview workflow. A + dispatch ran pull request code with write access to the default branch's + GitHub Actions cache. Previews are now published only from the + `publish-preview` and `publish-docker-preview` labels. + ## 2.15.10 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed9ee2b0..cb34eaeb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,19 +44,16 @@ needs testing: `socketdev/cli:pr-` image to Docker Hub and adds or updates a pull request comment with the image tag. -Both label-triggered and manually dispatched previews are limited to open pull -requests whose branches belong to this repository. Each label is handled as a -separate event, so applying both labels starts two workflow runs. Use manual -dispatch instead when both artifacts should be published in a single run. +Previews are limited to open pull requests whose branches belong to this +repository. Each label is handled as a separate event, so applying both labels +starts two workflow runs. The workflow reacts when a label is added; pushing another commit while the label remains on the pull request does not publish a new preview. To publish the new pull request head or retry a failed publication, remove the relevant label and apply it again. -Maintainers can also open **Actions > Publish PR Preview > Run workflow**, run -it from the repository's default branch, enter the pull request number, and -choose whether to publish to TestPyPI, Docker Hub, or both. When testing the CLI -against an SDK preview, enter the exact TestPyPI `socketdev` prerelease in -`sdk_preview_version`; publish the SDK preview first and allow time for -TestPyPI to expose it before starting the CLI Docker preview. +The workflow has no manual dispatch trigger. A dispatch from the default branch +would build pull request code with write access to the default branch's Actions +cache, so previews are only published from label events, which run in the pull +request's own cache scope. diff --git a/pyproject.toml b/pyproject.toml index 062b5a9d..01bbbb60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.15.10" +version = "2.15.11" requires-python = ">= 3.11" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 967132e7..fa91eedb 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,4 +1,4 @@ __author__ = 'socket.dev' -__version__ = '2.15.10' +__version__ = '2.15.11' USER_AGENT_NAME = 'socket-python-cli' USER_AGENT = f'{USER_AGENT_NAME}/{__version__}' diff --git a/socketsecurity/fossa_compat.py b/socketsecurity/fossa_compat.py index 0be11a9c..a02bdc9d 100644 --- a/socketsecurity/fossa_compat.py +++ b/socketsecurity/fossa_compat.py @@ -192,24 +192,28 @@ def _build_epss(props: dict[str, Any]) -> dict[str, Any]: } +# CVSS base metrics, as (FOSSA metric name, Socket alert prop key). +_CVSS_METRIC_FIELDS = ( + ("Attack Vector", "attackVector"), + ("Attack Complexity", "attackComplexity"), + ("Privileges Required", "privilegesRequired"), + ("User Interaction", "userInteraction"), + ("Scope", "scope"), + ("Confidentiality Impact", "confidentialityImpact"), + ("Integrity Impact", "integrityImpact"), + ("Availability Impact", "availabilityImpact"), +) + + def _build_metrics(props: dict[str, Any]) -> list[dict[str, Any]]: metrics = props.get("metrics") if isinstance(metrics, list): return metrics - metric_map = [ - ("Attack Vector", props.get("attackVector")), - ("Attack Complexity", props.get("attackComplexity")), - ("Privileges Required", props.get("privilegesRequired")), - ("User Interaction", props.get("userInteraction")), - ("Scope", props.get("scope")), - ("Confidentiality Impact", props.get("confidentialityImpact")), - ("Integrity Impact", props.get("integrityImpact")), - ("Availability Impact", props.get("availabilityImpact")), - ] + metric_values = ((name, props.get(key)) for name, key in _CVSS_METRIC_FIELDS) return [ {"name": name, "value": value} - for name, value in metric_map + for name, value in metric_values if value not in (None, "") ] diff --git a/uv.lock b/uv.lock index 68f33bef..c5990c81 100644 --- a/uv.lock +++ b/uv.lock @@ -1334,7 +1334,7 @@ wheels = [ [[package]] name = "socketsecurity" -version = "2.15.10" +version = "2.15.11" source = { editable = "." } dependencies = [ { name = "beautifulsoup4" },