Repository navigation
Commit e99c87c
committed
fix(security): scope cleanup endpoints and harden backup PIN storage
Closes the two GitHub security advisories still open against this repo.
The other four were remediated in #244-#249.
GHSA-2wqx-qppx-4rgf (High) -- cleanup endpoints:
/api/cleanup/legacy-messages and /api/cleanup/empty-conversations
authenticated with getSession(), which reads the cookie without
re-validating the JWT against the auth server, and then operated
platform-wide: legacy-messages selected and deleted up to 1000 matching
messages with no user filter at all, and empty-conversations enumerated
every conversation in the table. Both now use getUser(), resolve the
internal user id, and scope every query to the caller -- matching the
pattern already used by cleanup/legacy-keys.
GHSA-jpfm-vrpc-p6rr (Medium) -- backup PIN:
PINs were hashed with unsalted SHA-256, while users_select_authenticated
lets any logged-in account read every row of `users`, so one throwaway
signup could dump every backup_pin_hash and reverse the 6-12 digit
keyspace with a precomputed table.
Narrowing the RLS policy alone does not fix this -- the app legitimately
reads other users' rows and several callers do select('*'), which a
column-level REVOKE would break. So the credential column moves out of
`users` into user_backup_pins, a table anon and authenticated hold no
privileges on. New PINs are derived with scrypt (N=16384, r=8, p=1) over
a per-user random salt.
The old digests are discarded rather than relocated: nothing verified
them server-side, they only ever backed the hasPin boolean, and being
reversible is the entire problem. Row existence preserves hasPin for the
5 affected users.
The column drop is a separate migration (20260815120100) because it must
not land until this code is deployed. 20260815120000 is additive and is
already applied to prod.1 parent 4a3b54b commit e99c87c
9 files changed
Lines changed: 637 additions & 118 deletions
File tree
- src/app/api
- auth/backup-pin
- cleanup
- empty-conversations
- legacy-messages
- users/by-username/[username]
- supabase/migrations
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
8 | 15 | | |
9 | 16 | | |
10 | 17 | | |
| |||
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
97 | 115 | | |
98 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
99 | 122 | | |
100 | | - | |
| 123 | + | |
| 124 | + | |
101 | 125 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
108 | 151 | | |
109 | 152 | | |
110 | 153 | | |
| |||
118 | 161 | | |
119 | 162 | | |
120 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
121 | 173 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
126 | 178 | | |
127 | 179 | | |
128 | 180 | | |
129 | 181 | | |
130 | 182 | | |
131 | 183 | | |
132 | | - | |
| 184 | + | |
133 | 185 | | |
134 | 186 | | |
135 | 187 | | |
| |||
164 | 216 | | |
165 | 217 | | |
166 | 218 | | |
167 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
168 | 226 | | |
169 | 227 | | |
170 | | - | |
171 | | - | |
172 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
173 | 236 | | |
174 | 237 | | |
175 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | | - | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | | - | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
44 | 62 | | |
45 | 63 | | |
46 | 64 | | |
| |||
52 | 70 | | |
53 | 71 | | |
54 | 72 | | |
| 73 | + | |
55 | 74 | | |
56 | 75 | | |
| 76 | + | |
57 | 77 | | |
58 | 78 | | |
59 | 79 | | |
| |||
119 | 139 | | |
120 | 140 | | |
121 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
122 | 195 | | |
123 | 196 | | |
124 | 197 | | |
| |||
0 commit comments