Skip to content

Commit 0d0e97f

Browse files
committed
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.
1 parent bd81c2f commit 0d0e97f

7 files changed

Lines changed: 38 additions & 68 deletions

File tree

‎.github/workflows/pr-preview.yml‎

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,14 @@ name: Publish PR Preview
33
on:
44
pull_request:
55
types: [labeled]
6-
workflow_dispatch:
7-
inputs:
8-
pr_number:
9-
description: Pull request number to publish
10-
required: true
11-
type: string
12-
publish_test_pypi:
13-
description: Publish the Python package to TestPyPI
14-
required: true
15-
default: true
16-
type: boolean
17-
publish_docker:
18-
description: Publish socketdev/cli:pr-<number> to Docker Hub
19-
required: true
20-
default: false
21-
type: boolean
22-
sdk_preview_version:
23-
description: Optional exact TestPyPI socketdev prerelease for the Docker image
24-
required: false
25-
type: string
266

277
concurrency:
28-
group: publish-pr-preview-${{ github.event.pull_request.number || github.run_id }}
8+
group: publish-pr-preview-${{ github.event.pull_request.number }}
299
cancel-in-progress: false
3010

3111
jobs:
3212
context:
3313
if: >-
34-
github.event_name == 'workflow_dispatch' ||
3514
(github.event.label.name == 'publish-preview' ||
3615
github.event.label.name == 'publish-docker-preview') &&
3716
github.event.pull_request.head.repo.full_name == github.repository
@@ -48,28 +27,15 @@ jobs:
4827
id: context
4928
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
5029
env:
51-
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
5230
EVENT_PR_NUMBER: ${{ github.event.pull_request.number }}
53-
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
54-
WORKFLOW_REF: ${{ github.ref }}
5531
with:
5632
script: |
57-
const rawPrNumber = context.eventName === 'workflow_dispatch'
58-
? process.env.INPUT_PR_NUMBER
59-
: process.env.EVENT_PR_NUMBER;
33+
const rawPrNumber = process.env.EVENT_PR_NUMBER;
6034
if (!/^[1-9][0-9]*$/.test(rawPrNumber || '')) {
6135
core.setFailed('Pull request number must contain ASCII digits only.');
6236
return;
6337
}
6438
65-
if (context.eventName === 'workflow_dispatch') {
66-
const defaultRef = `refs/heads/${process.env.DEFAULT_BRANCH}`;
67-
if (process.env.WORKFLOW_REF !== defaultRef) {
68-
core.setFailed(`Run manual previews from ${defaultRef}.`);
69-
return;
70-
}
71-
}
72-
7339
const prNumber = Number(rawPrNumber);
7440
if (!Number.isSafeInteger(prNumber)) {
7541
core.setFailed('Pull request number is outside the supported range.');
@@ -162,9 +128,7 @@ jobs:
162128

163129
publish-package:
164130
needs: [context, build]
165-
if: >-
166-
github.event.label.name == 'publish-preview' ||
167-
(github.event_name == 'workflow_dispatch' && inputs.publish_test_pypi)
131+
if: github.event.label.name == 'publish-preview'
168132
runs-on: ubuntu-latest
169133
timeout-minutes: 10
170134
permissions:
@@ -228,9 +192,7 @@ jobs:
228192
229193
publish-docker:
230194
needs: [context, build]
231-
if: >-
232-
github.event.label.name == 'publish-docker-preview' ||
233-
(github.event_name == 'workflow_dispatch' && inputs.publish_docker)
195+
if: github.event.label.name == 'publish-docker-preview'
234196
runs-on: ubuntu-latest
235197
timeout-minutes: 15
236198
permissions:
@@ -274,8 +236,6 @@ jobs:
274236
# arm64 layer builds under emulation, so expect roughly double the runtime.
275237
platforms: linux/amd64,linux/arm64
276238
tags: socketdev/cli:pr-${{ needs.context.outputs.pr_number }}
277-
build-args: |
278-
SDK_PREVIEW_VERSION=${{ inputs.sdk_preview_version }}
279239

280240
- name: Comment on pull request
281241
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 2.15.11
4+
5+
### Security
6+
7+
- Removed the manual dispatch trigger from the pull request preview workflow. A
8+
dispatch ran pull request code with write access to the default branch's
9+
GitHub Actions cache. Previews are now published only from the
10+
`publish-preview` and `publish-docker-preview` labels.
11+
312
## 2.15.10
413

514
### Added

‎CONTRIBUTING.md‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,16 @@ needs testing:
4444
`socketdev/cli:pr-<pull-request-number>` image to Docker Hub and adds or
4545
updates a pull request comment with the image tag.
4646

47-
Both label-triggered and manually dispatched previews are limited to open pull
48-
requests whose branches belong to this repository. Each label is handled as a
49-
separate event, so applying both labels starts two workflow runs. Use manual
50-
dispatch instead when both artifacts should be published in a single run.
47+
Previews are limited to open pull requests whose branches belong to this
48+
repository. Each label is handled as a separate event, so applying both labels
49+
starts two workflow runs.
5150

5251
The workflow reacts when a label is added; pushing another commit while the
5352
label remains on the pull request does not publish a new preview. To publish the
5453
new pull request head or retry a failed publication, remove the relevant label
5554
and apply it again.
5655

57-
Maintainers can also open **Actions > Publish PR Preview > Run workflow**, run
58-
it from the repository's default branch, enter the pull request number, and
59-
choose whether to publish to TestPyPI, Docker Hub, or both. When testing the CLI
60-
against an SDK preview, enter the exact TestPyPI `socketdev` prerelease in
61-
`sdk_preview_version`; publish the SDK preview first and allow time for
62-
TestPyPI to expose it before starting the CLI Docker preview.
56+
The workflow has no manual dispatch trigger. A dispatch from the default branch
57+
would build pull request code with write access to the default branch's Actions
58+
cache, so previews are only published from label events, which run in the pull
59+
request's own cache scope.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.15.10"
9+
version = "2.15.11"
1010
requires-python = ">= 3.11"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

‎socketsecurity/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.15.10'
2+
__version__ = '2.15.11'
33
USER_AGENT_NAME = 'socket-python-cli'
44
USER_AGENT = f'{USER_AGENT_NAME}/{__version__}'

‎socketsecurity/fossa_compat.py‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,28 @@ def _build_epss(props: dict[str, Any]) -> dict[str, Any]:
192192
}
193193

194194

195+
# CVSS base metrics, as (FOSSA metric name, Socket alert prop key).
196+
_CVSS_METRIC_FIELDS = (
197+
("Attack Vector", "attackVector"),
198+
("Attack Complexity", "attackComplexity"),
199+
("Privileges Required", "privilegesRequired"),
200+
("User Interaction", "userInteraction"),
201+
("Scope", "scope"),
202+
("Confidentiality Impact", "confidentialityImpact"),
203+
("Integrity Impact", "integrityImpact"),
204+
("Availability Impact", "availabilityImpact"),
205+
)
206+
207+
195208
def _build_metrics(props: dict[str, Any]) -> list[dict[str, Any]]:
196209
metrics = props.get("metrics")
197210
if isinstance(metrics, list):
198211
return metrics
199212

200-
metric_map = [
201-
("Attack Vector", props.get("attackVector")),
202-
("Attack Complexity", props.get("attackComplexity")),
203-
("Privileges Required", props.get("privilegesRequired")),
204-
("User Interaction", props.get("userInteraction")),
205-
("Scope", props.get("scope")),
206-
("Confidentiality Impact", props.get("confidentialityImpact")),
207-
("Integrity Impact", props.get("integrityImpact")),
208-
("Availability Impact", props.get("availabilityImpact")),
209-
]
213+
metric_values = ((name, props.get(key)) for name, key in _CVSS_METRIC_FIELDS)
210214
return [
211215
{"name": name, "value": value}
212-
for name, value in metric_map
216+
for name, value in metric_values
213217
if value not in (None, "")
214218
]
215219

‎uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)