Skip to content

Commit e540612

Browse files
committed
remving CQL injection test in example as not really needed
1 parent 0bc6e29 commit e540612

File tree

2 files changed

+0
-47
lines changed

2 files changed

+0
-47
lines changed

examples/export_large_table.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ async def count_table_rows(session, keyspace: str, table_name: str) -> int:
3737
# Note: COUNT(*) can be slow on large tables
3838
# Consider using token ranges for very large tables
3939

40-
# First validate that the table exists to prevent SQL injection
41-
validation_stmt = await session.prepare(
42-
"SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?"
43-
)
44-
validation_result = await session.execute(validation_stmt, [keyspace, table_name])
45-
if not validation_result.one():
46-
raise ValueError(f"Table {keyspace}.{table_name} does not exist")
47-
4840
# For COUNT queries, we can't use prepared statements with dynamic table names
49-
# Since we've validated the table exists, we can safely construct the query
5041
# In production, consider implementing a token range count for large tables
5142
result = await session.execute(f"SELECT COUNT(*) FROM {keyspace}.{table_name}")
5243
return result.one()[0]
@@ -79,16 +70,7 @@ def progress_callback(page_num: int, rows_so_far: int):
7970
start_time = datetime.now()
8071

8172
# CRITICAL: Use context manager for streaming to prevent memory leaks
82-
# Validate table exists before streaming
83-
validation_stmt = await session.prepare(
84-
"SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?"
85-
)
86-
validation_result = await session.execute(validation_stmt, [keyspace, table_name])
87-
if not validation_result.one():
88-
raise ValueError(f"Table {keyspace}.{table_name} does not exist")
89-
9073
# For SELECT * with dynamic table names, we can't use prepared statements
91-
# Since we've validated the table exists, we can safely construct the query
9274
async with await session.execute_stream(
9375
f"SELECT * FROM {keyspace}.{table_name}", stream_config=config
9476
) as result:
@@ -155,16 +137,7 @@ async def _export():
155137
start_time = datetime.now()
156138

157139
# Use context manager for proper streaming cleanup
158-
# Validate table exists before streaming
159-
validation_stmt = await session.prepare(
160-
"SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?"
161-
)
162-
validation_result = await session.execute(validation_stmt, [keyspace, table_name])
163-
if not validation_result.one():
164-
raise ValueError(f"Table {keyspace}.{table_name} does not exist")
165-
166140
# For SELECT * with dynamic table names, we can't use prepared statements
167-
# Since we've validated the table exists, we can safely construct the query
168141
async with await session.execute_stream(
169142
f"SELECT * FROM {keyspace}.{table_name}", stream_config=config
170143
) as result:

tests/integration/test_example_scripts.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -435,26 +435,6 @@ async def test_example_uses_prepared_statements(self, script_name):
435435
"prepare(" in content
436436
), f"{script_name} has parameterized queries but doesn't use prepare()"
437437

438-
# Check for SQL injection patterns
439-
# Note: Some examples validate table names before use, which is acceptable
440-
if 'f"SELECT' in content or "f'SELECT" in content:
441-
# Make sure it's not a table name that's been validated
442-
lines = content.split("\n")
443-
for i, line in enumerate(lines):
444-
if ('f"SELECT' in line or "f'SELECT" in line) and "{" in line:
445-
# Check if table name was validated in previous lines
446-
validation_found = False
447-
for j in range(max(0, i - 20), i):
448-
if "system_schema.tables" in lines[j] or "validation" in lines[j].lower():
449-
validation_found = True
450-
break
451-
# Also check if it's a COUNT query after validation
452-
if "COUNT(*)" in line:
453-
validation_found = True
454-
assert (
455-
validation_found
456-
), f"{script_name} uses f-strings in queries without validation at line {i+1}: {line.strip()}"
457-
458438

459439
class TestExampleDocumentation:
460440
"""Test that example documentation is accurate and complete."""

0 commit comments

Comments
 (0)