Skip to content

[M0.6] Custom Semgrep rules - #12

Merged
samuelmbabhazi merged 3 commits into
mainfrom
feat/m0.6-semgrep-rule-tests
Nov 3, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
feat/m0.6-semgrep-rule-tests

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

[M0.6] Custom Semgrep rules. Closes #6

What changed

  • Rules moved to .semgrep/rules/shipkeep-rules.yml, tests in .semgrep/tests/shipkeep-rules.go and .semgrep/tests/shipkeep-rules.ts. Semgrep's test mode pairs the two directories by file name; every ruleid: line must be flagged by the named rule and every ok: line must stay silent. 8 of 8 rules pass.
  • Rules extended from the starter set, as THREAT_MODEL asks:
    • go-no-shell-interpreter: any shell as the program, under any path (sh, bash, dash, ash, zsh, ksh, fish, busybox, cmd, powershell, pwsh), via a metavariable regex instead of a fixed list.
    • go-exec-non-literal-binary (unchanged): program must be a string literal.
    • go-exec-dash-c (new): a -c argument to any program.
    • go-no-raw-process-spawn (new): syscall.Exec, syscall.ForkExec, syscall.StartProcess, os.StartProcess.
    • go-no-privileged-container (new): Docker HostConfig with Privileged: true or host PID, IPC, network or user namespaces (THREAT_MODEL E1), ready for M1.4.
    • ts-no-child-process: now also zx, cross-spawn, node-pty, require() and dynamic import() forms.
    • ts-no-prisma-unsafe-raw (unchanged).
    • ts-no-dynamic-code (new): eval, new Function, Function(), string arguments to setTimeout and setInterval.
  • Security workflow: the scan reads .semgrep/rules; the rule-test step always runs. pnpm semgrep:test and pnpm semgrep:scan for local use (Semgrep installed separately).
  • THREAT_MODEL lists the rules; .semgrep/tests excluded from Prettier so annotations stay put.

Why

Acceptance of M0.6: the security workflow fails on the bad samples and passes on the codebase. Rules without tests silently stop matching when patterns drift.

How it was tested

  • semgrep --test --config .semgrep/rules .semgrep/tests: 8/8 passed (Semgrep 1.183.0 locally, same version pinned in CI).
  • semgrep scan --config .semgrep/rules --exclude .semgrep/tests --error on the repository: no findings.
  • actionlint, prettier --check, pnpm nx run-many -t lint: clean.

Security considerations

Static guards only. Note that semgrep --test with a single rule file and a test directory crashes in Semgrep 1.183.0 (IndexError in path pairing); the rules/tests directory layout avoids it.

Checklist

  • Acceptance criteria from docs/PLAN.md are met and the task is ticked
  • Lint, TS tests, Go tests and buf lint pass
  • Tests added (annotated Semgrep samples)
  • No new shell invocation and no new secret exposure path
  • Audit events: not applicable
  • THREAT_MODEL updated

@samuelmbabhazi
samuelmbabhazi merged commit 8d79117 into main Nov 3, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m0.6-semgrep-rule-tests branch November 3, 2026 11:23
samuelmbabhazi added a commit that referenced this pull request Nov 28, 2026
…epository (closes #214) (#560)

Closes #214 (M3.2, shipkeep.yml sync), last of four pull requests. **UI
change: waits for the maintainer's validation before merging.** It is
stacked on #559, which is stacked on #558: until they merge, their
commits show here too. This PR's commits start at "the preview of a
change says how it is written".

#214's acceptance criterion is "editing replicas in the UI opens a PR
with the exact YAML change". It is tested in Chromium on the production
build.

## What changed

- **Web, `RepositoryConfigEditor`.** The Configuration section of a Git
application (`?tab=config&section=yml`) no longer shows the stored
configuration read-only: it edits the repository's file.
- The draft starts from the file's text, comments included (`GET
…/repository-config`).
  - The card says which file the application runs:
    - this file, at a given commit;
    - an older commit, when the branch has moved on (drift);
- or that the file is not a valid configuration for this application.
- **Review changes** checks the draft here (YAML, schema, same name),
then shows the control plane's preview: the exact lines written, with
three around each and `⋯ N unchanged lines` for the rest.
- The button names what happens: **Open a pull request**, with "It goes
to a branch of its own, in a pull request into main", or **Commit to
main**, with "If main is protected, a pull request is opened instead".
It sends the document reviewed, with the blob it was reviewed against.
- **Once written,** the card says "Pull request #12 opened. Merging it
into main deploys the change." or "Committed to main…", with **Open on
GitHub**. The draft starts again from the branch's file, so the change
is not written twice.
- **A file changed in the repository meanwhile** (409
`config_file_changed`) keeps the draft and offers **Load the latest
file**; the draft is then reviewed against it.
- New strings are translated in `fr.ts`. The read-only notice they
replace is removed.
- **API:** the preview also answers `writeMode` (the project's
`gitWriteMode`), for the button.
- **Fix: new projects defaulted to `commit`.** The dashboard's **New
project** dialog sent `gitWriteMode: 'commit'` since the design port
(#249). That goes against ADR 0031, which makes a change from the
interface a pull request unless the project says otherwise. With this
editor, every project created there would have committed straight to its
branch. It now sends `pull_request`, the database's default; the project
settings still change it. The Chromium test is what found this.
- **Docs:** SPEC describes the editor and the default.

## How it was tested

- **Web unit** (`repository-config-editor.spec.ts`, 7 tests):
- the file's text, comments included, as the draft, and the state shown
when the application runs it;
  - drift with both commits, and an invalid file;
- a review sending the parsed document and the blob, with the diff shown
(skipped run, added lines) and the pull request sentence;
- writing that sends the document reviewed, shows "Pull request #12" and
its link, then reloads the branch's file;
  - commit mode's text and button;
- a conflict that keeps the draft, loads the latest file and reviews
against its new blob;
- invalid YAML, a renamed application and an unchanged draft, refused
here with no call;
  - an unreadable file, read again.
- **Web unit, overall:** 411/411, including the New project body, now
`pull_request`.
- **Chromium, production build and CSP** (`github.browser.spec.ts`, new
test):
- an application created from a repository through the fake GitHub, its
file shown with comments;
- `scale.replicas: 3` added, then reviewed, with `+ replicas: 3` in the
diff;
- **Open a pull request** answers 201. GitHub received, on a
`shipkeep/config-<12 hex>` branch, **exactly the file with those lines
added**, and a pull request into `main` titled "Change the configuration
of billing";
- the link points to the pull request, the editor holds the branch's
file again, axe passes, and there are no console or CSP errors.
  - The whole browser suite passes, 31/31.
- **API:** unit 1016/1016; integration for the repository config (with
`writeMode`), the route matrix, and project resources. Lint, typecheck
and format clean.

Screenshots (desktop and mobile) are on the validation page linked in
the conversation with the maintainer.

## Security considerations

- The interface only calls the routes of #558 and #559: the document is
validated again there, written over the blob it was reviewed against,
with a token for one repository, and audited.
- The new-project fix restores the more reversible default, a pull
request, for every project created from the dashboard.
- The external link to GitHub is the URL the control plane validated
(`https://github.com` only), opened with `rel="noopener"`.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* View and edit an application’s repository configuration in the
dashboard, with validation and a preview of the exact changes.
* Submit reviewed changes as a commit or pull request, based on project
settings. Concurrent file changes are detected so you can reload and
review before writing.
* New projects use pull requests as the default for repository
configuration changes. Changes take effect after they’re pushed and
applied.
* **Documentation**
* Added guidance for repository configuration editing, previews, write
options, and request limits.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: samuel mbabhazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[M0.6] Custom Semgrep rules

1 participant