Skip to content

Commit 1be0688

Browse files
committed
fix: harden action security and mermaid diff
1 parent a616ee9 commit 1be0688

19 files changed

Lines changed: 513 additions & 209 deletions

.codeboarding/static_analysis.pkl

-108 Bytes
Binary file not shown.

.github/workflows/example-usage.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/test-self.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,36 @@ on:
55
branches: [main]
66
pull_request:
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
unittest:
1013
runs-on: ubuntu-latest
1114
steps:
1215
- uses: actions/checkout@v4
16+
with:
17+
persist-credentials: false
1318
- uses: actions/setup-python@v5
1419
with:
1520
python-version: '3.13'
1621
- name: Run unit tests (stdlib only)
1722
run: python -m unittest discover -s tests -v
23+
24+
lint:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
persist-credentials: false
30+
- uses: actions/setup-go@v5
31+
with:
32+
go-version: '1.22'
33+
- name: Install shellcheck
34+
run: sudo apt-get update && sudo apt-get install -y shellcheck
35+
- name: Install actionlint
36+
run: go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.7
37+
- name: Run actionlint
38+
run: actionlint
39+
- name: Run shellcheck
40+
run: shellcheck scripts/run_local.sh

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ test_codeboarding/
55
# Local test harness output (scripts/run_local.sh)
66
.cb-local/
77

8+
# Dependencies
9+
node_modules/
10+
11+
# Python generated files
12+
__pycache__/
13+
*.py[cod]
14+
15+
# CodeBoarding generated cache/log artifacts
16+
.codeboarding/static_analysis.pkl
17+
.codeboarding/static_analysis.sha
18+
.codeboarding/logs/
19+
.codeboarding/health/*
20+
!.codeboarding/health/
21+
!.codeboarding/health/health_report.json
22+
823
# Environment files
924
.env
1025

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ on:
2929
types: [created]
3030

3131
permissions:
32-
pull-requests: write # the only permission needed — nothing is pushed
32+
contents: read # checkout + fetch PR/base commits
33+
pull-requests: write # post/update the PR comment
34+
issues: write # issue_comment command reactions/comments
3335

3436
# Cancel a superseded run when new commits land on the same PR (avoid stacking
3537
# multi-minute LLM jobs).
@@ -40,13 +42,11 @@ concurrency:
4042
jobs:
4143
diagram:
4244
runs-on: ubuntu-latest
43-
# Run on (non-draft) PR events, OR when a TRUSTED collaborator comments exactly
44-
# "/codeboarding" on a PR. The if-gate matters: (1) without it a runner spins up
45-
# for every comment; (2) the author_association check is a SECURITY gate — see below.
45+
# Run on (non-draft) PR events, OR when a TRUSTED collaborator comments on a PR.
46+
# The action itself checks whether the first word matches `trigger_command`.
4647
if: >
4748
(github.event_name == 'pull_request' && github.event.pull_request.draft == false) ||
4849
(github.event_name == 'issue_comment' && github.event.issue.pull_request != null &&
49-
(github.event.comment.body == '/codeboarding' || startsWith(github.event.comment.body, '/codeboarding ')) &&
5050
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))
5151
timeout-minutes: 60
5252
steps:
@@ -61,7 +61,7 @@ You need **one secret**: an LLM API key. OpenRouter is the default; pass your ow
6161

6262
### On-demand: the `/codeboarding` command
6363

64-
Comment **`/codeboarding`** on any pull request to (re)run the diagram on demand — handy after the engine/baseline changes, or on draft PRs you don't auto-review. The action reacts with 👀 to acknowledge. Change the word via the `trigger_command` input.
64+
Comment **`/codeboarding`** on any same-repository pull request to (re)run the diagram on demand — handy after the engine/baseline changes, or on draft PRs you don't auto-review. The action reacts with 👀 to acknowledge. Change the word via the `trigger_command` input.
6565

6666
> **Note:** GitHub runs `issue_comment` workflows from the **default branch's** copy of the workflow file. So the command only works once this workflow is merged to your default branch — a workflow that exists only on a feature branch won't respond to comments.
6767

@@ -87,7 +87,7 @@ Comment **`/codeboarding`** on any pull request to (re)run the diagram on demand
8787
| Output | Description |
8888
|---|---|
8989
| `diagram_md` | Path to the rendered ```` ```mermaid ```` block in the runner workspace. |
90-
| `n_changed` | Number of top-level components added/modified/deleted. |
90+
| `n_changed` | Number of components added/modified/deleted, counted recursively. |
9191
| `truncated` | `true` if the diagram was reduced to changed-only to fit GitHub's Mermaid limit. |
9292

9393
## How the diff is colored
@@ -117,7 +117,7 @@ If `.codeboarding/analysis.json` isn't committed at the PR base commit, the acti
117117

118118
## Fork PRs
119119

120-
Because nothing is pushed (the diagram is inline Mermaid), there is no image step to skip on forks. The one caveat is GitHub's own policy: **secrets are withheld from `pull_request`-triggered runs on forks**, so the LLM key is unavailable and the run fails early with a clear message. A maintainer can re-run from the Actions tab, or use `pull_request_target` if you understand its security implications.
120+
Because nothing is pushed (the diagram is inline Mermaid), there is no image step to skip on forks. The one caveat is GitHub's own policy: **secrets are withheld from `pull_request`-triggered runs on forks**, so the LLM key is unavailable and the run fails early with a clear message. Do not use `pull_request_target` for this action; it would analyze PR-head code while secrets are available. The trusted `/codeboarding` `issue_comment` path is intentionally limited to same-repository PRs, so fork code is not analyzed with repository secrets present.
121121

122122
## Limitations
123123

0 commit comments

Comments
 (0)