fix(security): SQL injection vulnerabilities in postgres_datastore.py#490
Open
deosha wants to merge 1 commit intoopenai:mainfrom
Open
fix(security): SQL injection vulnerabilities in postgres_datastore.py#490deosha wants to merge 1 commit intoopenai:mainfrom
deosha wants to merge 1 commit intoopenai:mainfrom
Conversation
This commit addresses multiple SQL injection vulnerabilities in the PostgreSQL datastore provider identified by semantic taint analysis. ## Vulnerabilities Fixed 1. **delete_by_filters()** (Critical): Filter values were directly interpolated into SQL using f-strings, allowing SQL injection through document_id, source, source_id, author, start_date, or end_date parameters. 2. **upsert()**, **delete_like()**, **delete_in()**: Table and column names were used in f-strings without validation. ## Changes - Converted delete_by_filters() to use parameterized queries with %s placeholders - Added table/column name validation (alphanumeric + underscore only) to all methods - Added safety check to prevent accidental deletion when no filters specified ## Security Impact - Before: Attacker could execute arbitrary SQL via filter parameters - After: All user input properly parameterized or validated CWE-89: SQL Injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes multiple SQL injection vulnerabilities in the PostgreSQL datastore provider.
The Problem
The
delete_by_filters()method used f-string interpolation to build SQL queries with user-provided filter values:An attacker could inject arbitrary SQL through any of these filter parameters.
The Fix
delete_by_filters()to use%splaceholders with parameter tuplesSecurity Impact
CWE Reference
Identified using aisentry, an AI/LLM security scanner for OWASP LLM Top 10 vulnerabilities.