fix(nspd-geo): replace f-string bulk INSERT with parametrized execute (SQL injection fix) #123
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#123
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/nspd-geo-sql-injection"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Real SQL injection vector в
backend/app/workers/tasks/nspd_geo.py:298-310— per code review audit (May 14).Bulk INSERT в
enqueue_geo_jobстроил VALUES через f-string +chr(39)*2quote escape:Manual quote escape НЕ защищает от backslash escape / Unicode quote tricks. Exploitable если
cad_numпридёт из user input (e.g. через admin POST endpoint).Fix
SQLAlchemy
text+ list of dicts → psycopg v3 handles batch executemany. Pattern consistent с другими INSERT'ами в этом файле.Preserved
Test plan
ruff checkpassedPOST /admin/scrape/geo/jobsс любым cad_num — должен работать без SQL errorsVault
fixes/Bug_Nspd_Geo_Sql_Injection_May14.md— created.Closes audit critical #3.
Bot review — SECURITY FIX 🔒
Textbook-исправление SQL injection:
✅ f-string interpolation → SQLAlchemy
textс bind params (:job_id,:cad_num,:thematic_id)✅ Manual
chr(39)*2quote-escape removed — psycopg v3 handles escaping correctly✅ List-of-dicts batch → driver executemany (perf parity с bulk INSERT VALUES)
✅
ON CONFLICT (job_id, cad_num, thematic_id) DO NOTHINGсохранён verbatim✅ Function signature, return value, transaction/commit/close logic — нетронуты
✅ Pattern consistent с другими INSERT'ами в этом же файле
Минор
chr(39)escape был неполной защитой — backslash-escape и Unicode-quote tricks могли бы обойти. Этот fix полностью решает класс уязвимости в этом codepath. Стоит для consistency проверить, нет ли других f-string INSERT'ов вbackend/app/workers/tasks/— отдельным PR.CI
Мерджу когда оба зелёные. High priority — security fix.
Tracking: part of audit batch #127. Security: SQL injection fix. Vault:
fixes/Bug_Nspd_Geo_Sql_Injection_May14.md.Final review (SHA
08118f0, CI ✅) 🔒approve merge