Commit 8246234
Address Devin review: 4 RBAC auth path fixes
#1 internal-packages/rbac/src/ability.ts (severity: 🔴 silent privilege
escalation): buildJwtAbility was treating any scope starting with
`admin:` as a universal wildcard. Pre-RBAC, the legacy
checkAuthorization string-matched superScopes — `admin:sessions` only
granted access to routes that explicitly listed it. After the JWT-
ability split, the same scope was returning true for every action on
every resource. Restrict the bypass to bare `admin` (no second
segment); `admin:<type>` now flows through normal matching as
action="admin" against resources of that type. Adds 2 regression
tests in ability.test.ts.
#2 apps/webapp/app/services/routeBuilders/apiBuilder.server.ts (status
discard): authenticateRequestForApiBuilder hardcoded `status: 401`
even though BearerAuthResult.status is `401 | 403`. A plugin
returning 403 (e.g. suspended account, IP block) would silently get
downgraded to 401 — semantically wrong (401 = "who are you?", 403 =
"you're not allowed") and confusing for client retry logic. Plumb
result.status through.
#3 apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
(everyResource([]) vacuous truth): [].every() returns true, so
everyResource([]) was passing auth for any token. Not exploitable
today (Zod rejects empty bodies before auth), but the auth layer
should never grant on empty input. Same defensive guard added to
anyResource() for symmetry — only PERMISSIVE_ABILITY would have
granted there, but the pattern shouldn't depend on the ability's
choice.
#4 internal-packages/rbac/src/fallback.ts (PREVIEW env regression): the
fallback's authenticateBearer looked up environments by apiKey only,
skipping the branch-aware resolution that findEnvironmentByApiKey
does for PREVIEW envs. Self-hosters using preview/branch envs would
either fail or operate against the parent env. Mirror the legacy
path: read x-trigger-branch, include matching child env, and pivot
the resolved env to the child (apiKey/orgMember/organization/project
inherited from parent). sanitizeBranchName inlined here because
internal-packages can't import webapp code; comment notes the
duplication.
All four flagged by Devin's PR review. Cloud plugin's buildJwtAbility
gets the same #1 fix in a sibling commit on this PR's cloud branch.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5063f84 commit 8246234
4 files changed
Lines changed: 96 additions & 3 deletions
File tree
- apps/webapp/app/services/routeBuilders
- internal-packages/rbac/src
Lines changed: 15 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
| |||
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
161 | 170 | | |
162 | 171 | | |
163 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
164 | 177 | | |
165 | 178 | | |
166 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
69 | 92 | | |
70 | 93 | | |
71 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
87 | 96 | | |
88 | 97 | | |
89 | 98 | | |
| |||
108 | 117 | | |
109 | 118 | | |
110 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
111 | 146 | | |
112 | 147 | | |
113 | 148 | | |
| |||
276 | 311 | | |
277 | 312 | | |
278 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
279 | 330 | | |
280 | 331 | | |
281 | 332 | | |
| |||
0 commit comments