Repository navigation
Add Security rules for Appwrite PHP conventions - #14062
Conversation
Wire a Checks / Rules job into PR CI and the scheduled security scan so common skip, token-response, outbound-map, header-filter, and nested permission patterns fail the build instead of waiting on review. Co-authored-by: Jake Barnby <[email protected]>
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
Expand skip and token-response matching, drop screenshots path excludes in favor of WARNING review signal, and add client-IP and placeholder-secret checks. ERROR scan on current main stays clean. Co-authored-by: Jake Barnby <[email protected]>
Replace the userdata skip list with an allowlisted skip+load class, cover token/JWT output, related-permission name families, guest ROLE_GUESTS scopes, and guest URL params without PublicURL. Leave known screenshots sites as WARNING instead of path excludes. Co-authored-by: Jake Barnby <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…on PRs. Drop the named-collection ERROR leftover. Ungated skip+load of any non-allowlisted collection now fails CI; fixtures and prove.sh show a known-bad snippet fails and a gated skip does not. Checks / Rules upserts one sticky PR comment for WARNING (and ERROR) findings. Co-authored-by: Jake Barnby <[email protected]>
Rename `static- rules` to `static-rules`. GitHub job ids cannot contain spaces, which left Checks / Rules (and the rest of CI) unscheduled. Co-authored-by: Jake Barnby <[email protected]>
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
Replace the three-column table (160-char mid-sentence clip) with a bullet list of file:line, rule id, and the complete rule message. Drop whole findings only when the comment would exceed GitHub's size limit. Co-authored-by: Jake Barnby <[email protected]>
client-ip-header covers every forwarding header and accessor; the placeholder rule matches a literal class; guest URL and Assoc rules match any URL-like / map param on ROLE_GUESTS scopes and honour class ALLOWED_* allowlists; the token gate covers module action() methods and Key in any position; header-blocklist-filter is ERROR now that main is clean. Co-authored-by: Jake Barnby <[email protected]>
Every /v1 route needs a scope label, non-public routes need the api hook group, redirect-target params need redirectValidator, and guest-scoped writes without an abuse limit are surfaced as WARNING. Co-authored-by: Jake Barnby <[email protected]>
Dynamic code, process execution, disabled TLS verification, superglobals, request-wide authorization disable, showSensitive outside event payloads, non-cryptographic randomness, libxml entity loading, interpolated SQL, non-httponly cookies, debug output, and request-derived filesystem paths. Co-authored-by: Jake Barnby <[email protected]>
Secret env defaults, non-constant-time secret comparisons, any/guests write permissions, and outbound clients that follow redirects. Each has live findings on main and is listed on the sticky PR comment. Co-authored-by: Jake Barnby <[email protected]>
prove.sh runs the real ERROR scan on one known-bad snippet per ERROR rule, asserts the expected rule id, and checks a file of house patterns stays clean. README gains a full trigger matrix and rule-writing notes. Co-authored-by: Jake Barnby <[email protected]>
EncryptionKey on main declares the public default as a PLACEHOLDER constant and compares against it; constant propagation made every use an ERROR. Comparisons, warning/exception messages and a PLACEHOLDER constant are now ok, while another class's PLACEHOLDER as a getEnv default is caught explicitly. Co-authored-by: Jake Barnby <[email protected]>
…mment. The formatter reads each matched file from the checkout to resolve the HTTP method, path and scope (or hook, Class::method, init resource), then prints a per-rule What's wrong / How to fix built from the matched code, with a link to the scanned commit. Findings are grouped by rule so the full rule message appears once per group. Co-authored-by: Jake Barnby <[email protected]>
…-rules-eb3f Co-authored-by: Jake Barnby <[email protected]>
Co-authored-by: Jake Barnby <[email protected]>
Co-authored-by: Jake Barnby <[email protected]>
…nd Scan Rules. Co-authored-by: Jake Barnby <[email protected]>
Co-authored-by: Jake Barnby <[email protected]>
🟢 Tier S · Ready to merge
Adds 28 custom Semgrep security rules with PHP fixtures, scratch proofs, baseline enforcement, SARIF uploads, and sticky PR comments. The refreshed baseline records 32 existing warnings. The PR also adds native-crash checks to E2E CI jobs and updates transaction commits to resolve the target database, reject cross-instance operations, and claim commits under a lock with authorization-aware access. Latest changes: The newest commits add E2E native-crash checks, refresh the baseline, extend nested transaction-load fixtures, and update database resolution and atomic commit claiming.
📂 Walkthrough · 9
Reviewed the commits since |
…ard in request-path-to-filesystem. Co-authored-by: Jake Barnby <[email protected]>
… all-clear when semgrep.json is missing. Co-authored-by: Jake Barnby <[email protected]>
…ute at the same method is not baselined. Co-authored-by: Jake Barnby <[email protected]>
The atomic claim loads transactions inside an unconditional Authorization skip, which skip-ungated-load flags as ERROR. Gate it the same way as the first load so session users go through document ACL and only API keys or privileged callers skip. Drop the retired Assistant from the security-rules baseline after merging main, and cover the withTransaction skip shape in the fixture.
|
Follow-up after the last run:
Local: |
What does this PR do?
Adds Security rules under
.semgrep/for Appwrite PHP coding conventions and wires them into CI. Rules are written as general pattern classes with allowlists, not lists of files or collections. CI changes only; no product code changes.Checks / Rules(and the scheduledScan Rulesjob).<!-- semgrep-rules-comment -->) that is updated in place. Findings are grouped by rule. Each one has:file:linelink to the scanned commit;Class::method(), or the init resource;.semgrep/baseline.json) neither fail the job nor appear in detail on the comment. The comment shows them only as per-rule counts in a collapsed block. They are still written to SARIF.always(). Ifsemgrep.jsonis missing or unreadable (because the install, fixtures, proofs, or scan failed), the sticky comment says the scan did not complete and links the run. It does not post an all-clear.Baseline. Merging this PR does not change the result for other PRs.
.semgrep/baseline.jsonrecords the 32 findings on the current tree, which ismainmerged into this branch. Semgrep OSS only supports a commit-diff baseline, so.semgrep/baseline.jsfilters the JSON scan itself:checkprints totals, lists new findings and stale entries, and exits 1 on any new ERROR.updateregenerates the file.Entries are keyed on rule id, path, and the whitespace-collapsed matched text, so line shifts elsewhere in a file do not resurface them. When the match spans a module route chain, the
->setHttpPath(…)line is part of the key. A route is therefore identified by both method and path, and replacing a baselined route with a different one surfaces as new. The regeneration steps are in.semgrep/README.md.ERROR classes (23). These have 0 findings on the current tree.
route-without-scope(every/v1route declares a scope),route-without-api-group(non-public routes run the sharedapihooks),redirect-param-without-validatorskip-ungated-load,global-authorization-disable,related-permissions-helperaccount-token-secret-scope-gate(now covers moduleaction()methods andKeyin any position),show-sensitive-outside-payload,insecure-cookie-flagsguest-url-without-publicurl(any URL-like param name,URL()orText()),unbounded-map-to-outbound(anyAssocparam name; a class-levelALLOWED_*constant counts as filtered),header-blocklist-filterclient-ip-header(all forwarding headers and accessors, including host and proto)default-secret-placeholder(a class of placeholder literals),insecure-randomtls-verification-disabledunsafe-dynamic-code,shell-exec-in-handler,superglobal-in-handler,debug-output-in-handler,raw-sql-interpolation,xml-external-entities,request-path-to-filesystem(taint from request getters orstringaction params;realpath()alone does not sanitize, only a base-directory containment guard does)WARNING classes (5). These have 32 findings on the current tree, all in the baseline. A class can be promoted to ERROR once its entries are cleared.
guest-write-without-abuse-limitpermissive-write-permissionsecret-compare-timingweak-secret-env-default.semgrep/README.md):unserialize(...)and\unserialize(...).metavariable-regexso that negative conditions can still see the full chain.explainersin.github/workflows/semgrep-comment.js.Test Plan
semgrep test .semgreppasses 28/28. Every rule has a sibling.phpfixture withruleidandokcases.semgrep --validatereports 28 rules and 0 errors withbaseline.js/baseline.jsonpresent.request-path-to-filesystemfixture:file_get_contents(realpath($base . '/' . $request->getParam('path')))is flagged.realpath()result read without a check is flagged.realpath()result whose failedstr_starts_withcheck only logs is flagged.str_starts_withorsubstr+strlenguard, and inside a positivestr_starts_withbranch.app/controllers/general.php, which uses thesubstrguard, stays clean.bash .semgrep/prove.sh:PublicURL,redirectValidator,ALLOWED_HEADERS,getIP(),random_bytes, bound SQL,basename, httponly cookies, and event-payloadshowSensitive. A second clean file mirrorsEncryptionKey(aPLACEHOLDERconstant, comparisons against it, and aConsole::warningnaming it).src/Appwrite app/controllers app/init:baseline.js checkreports 32 baselined, 0 new ERROR, 0 new WARNING, and exits 0.Permission::write(Role::any())next to baselined lines gives 2 new WARNINGs (exit 0).eval($request->getParam(...))file gives 1 new ERROR (exit 1).setHttpPathof a baselined guest-write route (same method, still no abuse limit) gives 1 new WARNING and 1 stale entry.semgrep.jsonand a truncated one each replace the sticky comment with the "Scan did not complete" notice and a run link. This was checked against a stubbed GitHub client.Related PRs and Issues
Checklist