Commit 9d8a2ba
authored
security(dci): fail closed on unresolved search sender + cap page_size (#260)
* security(dci): fail closed on unresolved sender (search) + cap page_size
DCI search reached an unscoped sudo res.partner search whenever no active
sender was resolved: with sender=None/False, DCIConsentAdapter disengages
(build_consented_domain returns the base domain unchanged), so full PII is
returned. Three routes funnel into this: the sync search route, the async
search route, and bulk upload (all via DCISocialSearchService /
transaction.process_async_search). page_size was also unbounded (schema only
enforces > 0), enabling whole-registry enumeration in one request.
Fail closed across the shared sink and the request paths:
- routers/search.py: reject (403) when the verified sender doesn't resolve to
an active registered sender; never run with sender=None (removed `or None`).
- middleware/signature.py: verify_dci_signature requires an active sender, so a
deactivated sender cannot authenticate (keeps verify and resolution in sync).
- models/transaction.py: process_async_search refuses (rejected, no search)
when the transaction has no resolved sender -- the shared sink guard that
protects the async and bulk paths even before their route-level checks.
- routers/async_router.py: async_search rejects (403) an unresolved sender
instead of persisting sender_id=False and queuing an unscoped job.
- search_service.py: clamp page_size to dci.max_page_size (default 100).
The report's literal claim (service built without a sender) was already fixed
by 0944b7f; this closes the residual fail-open resolution + unbounded
page_size. Separately tracked follow-ups: bulk_upload accepts an UNSIGNED,
caller-asserted sender_id (impersonation -- needs signature binding), and the
dead consent domain (status=="active" matches nothing for require_consent
senders; functional, fail-closed).
Tests: unresolved/inactive sender -> 403 (sync + async) / 401 (signature);
sink refuses sender-less transaction; page_size clamped. spp_dci_server
325/325, spp_dci_server_social 75/75.
* fix(dci): address CI/review on the search consent hardening
- pre-commit (semgrep): ruff-format had wrapped the signature.py sudo lookup
across lines, pushing the nosemgrep off the matched `.sudo()` line. Keep
`.sudo()` on a single line with the nosemgrep directly above (and likewise
for the new search_service config read). Semgrep passes locally.
- transaction.py (Gemini security-high): a Many2one still dereferences a
DEACTIVATED record, and process_async_search runs asynchronously, so a sender
deactivated after the transaction was created would slip past `if not
self.sender_id`. Check `not self.sender_id.active` too (fail closed).
- search_service.py (Gemini medium): a misconfigured dci.max_page_size
(empty/non-integer) would crash int(); wrap in try/except, fall back to 100.
Tests: add a sink test for a deactivated sender -> refused.
spp_dci_server 326/326, spp_dci_server_social 75/75.
* security(dci): treat non-positive max_page_size as default, not no-cap
A non-positive dci.max_page_size (0 or negative) previously skipped the
page_size clamp entirely, silently disabling the cap and letting a client
pull an arbitrarily large page. Treat such a misconfiguration as the
default (100) so the cap can never be turned off by accident.
Addresses staff-review nit on PR #260.1 parent 9102547 commit 9d8a2ba
9 files changed
Lines changed: 245 additions & 21 deletions
File tree
- spp_dci_server_social
- services
- tests
- spp_dci_server
- middleware
- models
- routers
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
181 | 183 | | |
182 | | - | |
| 184 | + | |
| 185 | + | |
183 | 186 | | |
184 | 187 | | |
185 | | - | |
| 188 | + | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
213 | 230 | | |
214 | 231 | | |
215 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
150 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
151 | 153 | | |
152 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
153 | 164 | | |
154 | 165 | | |
155 | 166 | | |
| |||
171 | 182 | | |
172 | 183 | | |
173 | 184 | | |
174 | | - | |
| 185 | + | |
175 | 186 | | |
176 | 187 | | |
177 | 188 | | |
| |||
183 | 194 | | |
184 | 195 | | |
185 | 196 | | |
186 | | - | |
| 197 | + | |
187 | 198 | | |
188 | 199 | | |
189 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
102 | 120 | | |
103 | 121 | | |
104 | 122 | | |
105 | 123 | | |
106 | 124 | | |
107 | 125 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 126 | + | |
115 | 127 | | |
116 | 128 | | |
117 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 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 | + | |
| 195 | + | |
138 | 196 | | |
139 | 197 | | |
140 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
| |||
212 | 215 | | |
213 | 216 | | |
214 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
215 | 252 | | |
216 | 253 | | |
217 | 254 | | |
| |||
225 | 262 | | |
226 | 263 | | |
227 | 264 | | |
228 | | - | |
| 265 | + | |
229 | 266 | | |
230 | 267 | | |
231 | 268 | | |
| |||
251 | 288 | | |
252 | 289 | | |
253 | 290 | | |
254 | | - | |
| 291 | + | |
255 | 292 | | |
256 | 293 | | |
257 | 294 | | |
| |||
291 | 328 | | |
292 | 329 | | |
293 | 330 | | |
294 | | - | |
| 331 | + | |
295 | 332 | | |
296 | 333 | | |
297 | 334 | | |
| |||
320 | 357 | | |
321 | 358 | | |
322 | 359 | | |
323 | | - | |
| 360 | + | |
324 | 361 | | |
325 | 362 | | |
326 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
89 | 106 | | |
90 | 107 | | |
91 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
| 222 | + | |
222 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
223 | 235 | | |
224 | 236 | | |
225 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
494 | 551 | | |
495 | 552 | | |
496 | 553 | | |
| |||
0 commit comments