Table Whitelist
The whitelist system allows modifying specific tables even in read-only mode — ideal for giving AI assistants a temporary workspace.
Problem it solves
Section titled “Problem it solves”When using AI assistants with production databases, there’s a risk of:
- Accidental data deletion
- Data exfiltration with malicious queries like
DELETE temp_ai FROM temp_ai JOIN production_table - Unauthorized access to sensitive tables via JOINs or subqueries
Configuration
Section titled “Configuration”MSSQL_READ_ONLY=trueMSSQL_WHITELIST_TABLES=temp_ai,v_temp_iaValidation flow
Section titled “Validation flow”- User executes a query
- Basic input validation
- Read-only mode check
- Operation type extraction (INSERT/UPDATE/DELETE/etc.)
- Extraction of all referenced tables (FROM, JOIN, subqueries, CTEs)
- Validation that all tables are in the whitelist
- Execution or block with error
Multi-table detection
Section titled “Multi-table detection”The parser detects tables in:
FROMclausesJOINoperations (INNER, LEFT, RIGHT, FULL)- Subqueries:
SELECT * FROM (SELECT * FROM table) INSERT INTO ... SELECT ... FROMUPDATE ... SET col = (SELECT ... FROM)DELETE ... FROM ... JOIN- CTEs:
WITH cte AS (SELECT * FROM table)
Examples
Section titled “Examples”Allowed queries
Section titled “Allowed queries”-- SELECT always allowed (read-only)SELECT * FROM production_tableSELECT * FROM production_table JOIN temp_ai ON ...
-- Modifications on whitelisted tablesUPDATE temp_ai SET col = 'value' WHERE id = 1DELETE FROM temp_ai WHERE id = 1INSERT INTO temp_ai VALUES (1, 'test')Blocked queries
Section titled “Blocked queries”-- Modification of unauthorized tableUPDATE users SET password = 'hacked'-- Error: permission denied: table 'users' is not whitelisted
-- JOIN with unauthorized table in modificationDELETE temp_ai FROM temp_ai JOIN users ON temp_ai.id = users.id-- Error: permission denied: table 'users' is not whitelisted
-- Subquery to sensitive dataUPDATE temp_ai SET data = (SELECT password FROM users WHERE id = 1)-- Error: permission denied: table 'users' is not whitelisted
-- INSERT from unauthorized tableINSERT INTO temp_ai SELECT * FROM customers-- Error: permission denied: table 'customers' is not whitelistedSecurity logs
Section titled “Security logs”Each permission check is logged:
[SECURITY] Permission check - Operation: DELETE, Tables found: [temp_ai users], Whitelist: [temp_ai][SECURITY] SECURITY VIOLATION: Attempted DELETE on non-whitelisted table 'users'Recommendations for AI
Section titled “Recommendations for AI”Create dedicated temporary tables
Section titled “Create dedicated temporary tables”CREATE TABLE temp_ai ( id INT IDENTITY(1,1) PRIMARY KEY, operation_type VARCHAR(50), data NVARCHAR(MAX), created_at DATETIME DEFAULT GETDATE(), result NVARCHAR(MAX));Automate cleanup
Section titled “Automate cleanup”CREATE PROCEDURE CleanupTempAIASBEGIN DELETE FROM temp_ai WHERE created_at < DATEADD(day, -7, GETDATE());END;Limitations
Section titled “Limitations”The regex-based parser may not detect tables in:
- Highly obfuscated queries with nested comments
- Dynamic SQL within stored procedures
- CTEs with multiple levels of nesting
Mitigation: For maximum security, combine with database-level permissions (GRANT/DENY).