File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -152,20 +152,20 @@ def get_prompt_for_role(user_role):
152
152
cur = connection .cursor ()
153
153
logger .info ("Connected to RDS instance!" )
154
154
155
- # Validate the role
156
- valid_roles = ["public" , "educator" , "admin" ]
157
- if user_role not in valid_roles :
158
- logger .error (f"Invalid user_role: { user_role } " )
159
- return None
155
+ # Define a list of allowed role values (whitelist)
156
+ VALID_ROLES = ["public" , "educator" , "admin" ] # add all valid column names
157
+ if user_role not in VALID_ROLES :
158
+ raise ValueError (f"Invalid role specified: { user_role } " )
160
159
161
- # Query to fetch the most recent prompt for the specified role
162
- query = f"""
163
- SELECT { user_role }
160
+ query = """
161
+ SELECT {}
164
162
FROM prompts
165
- WHERE { user_role } IS NOT NULL
163
+ WHERE {} IS NOT NULL
166
164
ORDER BY time_created DESC NULLS LAST
167
165
LIMIT 1;
168
- """
166
+ """ .format (psycopg2 .extensions .quote_ident (user_role , cur ),
167
+ psycopg2 .extensions .quote_ident (user_role , cur ))
168
+
169
169
cur .execute (query )
170
170
result = cur .fetchone ()
171
171
logger .info (f"Query result for role { user_role } : { result } " )
You can’t perform that action at this time.
0 commit comments