Repository navigation
Commit 3c2c36d
authored
feat(security): fail-closed webhooks, API authentication, CORS hardening, and trusted Semgrep rules (#22)
## Summary
Hardens revue daemon against unauthenticated access, injection, and
untrusted rule execution:
1. **Fail-Closed Webhooks (CWE-306)**: Webhook signature verification
fails closed (returns `401 Unauthorized`) when no secret is configured,
unless explicitly opted-in with `--insecure-webhooks`.
2. **API Authentication (CWE-306)**: Mutating endpoints (`/api/trigger`,
`/api/feedback`, `/api/feedback/delete`, `/api/rules/synthesize`)
require `REVUE_API_KEY` via `Authorization: Bearer <key>` or
`X-Revue-Key: <key>`. When unset, access is strictly confined to
loopback clients (`127.0.0.1`, `::1`); remote callers receive `403
Forbidden`.
3. **CORS Hardening**: Replaced wildcard `allow_origin(Any)` with
configured `server.cors_origins` and standard local origins.
4. **Local Bind by Default**: Default listen address changed from
`0.0.0.0:8383` to `127.0.0.1:8383`.
5. **Trusted Semgrep Rule Isolation (CWE-829)**: Pass 0 AST scan loads
rules strictly from daemon config (`config.review.semgrep_config`) or
host repository, never from the untrusted PR checkout root.
6. **Path Traversal Sanitization (CWE-22)**: `resolve_repo_root` rejects
`..` and invalid path components.
7. **Unique Review Identifiers & Feedback Error Propagation**: Review
IDs are partitioned by repo and sequence counter
(`rev-manual-{repo}-{pr}-{seq}`); feedback DB write errors return `500`
instead of `200`.
## Verification
- Added unit tests for loopback restriction, API key authentication, and
traversal rejection.
- All 74 unit tests and benchmarks pass in Nix development shell.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **New Features**
* Added configurable API-key protection for review and feedback actions,
supporting bearer tokens and a dedicated request header. Keys can be set
in configuration, on the command line or through the environment.
* Webhooks require a secret by default; insecure mode can be enabled
through configuration or the command line.
* CORS access can be configured, with local development origins
supported.
* **Security**
* The daemon now listens on localhost by default. Without an API key,
API access is limited to loopback connections.
* Repository names with hidden or invalid path components are rejected.
* **Bug Fixes**
* Manual review records are retained separately, with clearer review
identifiers.
* Review scans use trusted rule configuration rather than configuration
from the scanned checkout.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 1aa5b0a commit 3c2c36d
7 files changed
Lines changed: 478 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
22 | 56 | | |
23 | 57 | | |
24 | 58 | | |
| |||
190 | 224 | | |
191 | 225 | | |
192 | 226 | | |
| 227 | + | |
193 | 228 | | |
194 | 229 | | |
195 | 230 | | |
| |||
242 | 277 | | |
243 | 278 | | |
244 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
245 | 284 | | |
246 | 285 | | |
247 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| |||
160 | 168 | | |
161 | 169 | | |
162 | 170 | | |
| 171 | + | |
| 172 | + | |
163 | 173 | | |
164 | 174 | | |
165 | 175 | | |
| |||
170 | 180 | | |
171 | 181 | | |
172 | 182 | | |
| 183 | + | |
| 184 | + | |
173 | 185 | | |
174 | 186 | | |
175 | 187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
| 232 | + | |
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | | - | |
| 238 | + | |
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
| |||
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
| 271 | + | |
| 272 | + | |
270 | 273 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
278 | 310 | | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
283 | 348 | | |
284 | 349 | | |
285 | 350 | | |
| |||
704 | 769 | | |
705 | 770 | | |
706 | 771 | | |
| 772 | + | |
707 | 773 | | |
708 | 774 | | |
709 | 775 | | |
710 | 776 | | |
711 | 777 | | |
712 | 778 | | |
713 | | - | |
| 779 | + | |
714 | 780 | | |
715 | 781 | | |
716 | 782 | | |
| |||
828 | 894 | | |
829 | 895 | | |
830 | 896 | | |
831 | | - | |
| 897 | + | |
832 | 898 | | |
833 | 899 | | |
834 | 900 | | |
| |||
870 | 936 | | |
871 | 937 | | |
872 | 938 | | |
| 939 | + | |
873 | 940 | | |
874 | 941 | | |
875 | 942 | | |
| |||
991 | 1058 | | |
992 | 1059 | | |
993 | 1060 | | |
| 1061 | + | |
994 | 1062 | | |
995 | 1063 | | |
996 | 1064 | | |
997 | 1065 | | |
998 | 1066 | | |
999 | 1067 | | |
1000 | 1068 | | |
| 1069 | + | |
1001 | 1070 | | |
1002 | 1071 | | |
1003 | 1072 | | |
| |||
0 commit comments