@@ -99,6 +99,71 @@ def list_tables(
9999 """
100100 ...
101101
102+ # ---------------------------------------------------------------------------
103+ # Intentionally Insecure Examples (FOR SNYK / SAST TESTING ONLY)
104+ # ---------------------------------------------------------------------------
105+ # These examples are NEVER executed at runtime (guarded by `if False:` below),
106+ # but are present so that static analysis / SAST tooling (e.g., Snyk Code) can
107+ # detect a representative variety of insecure coding patterns. Do NOT copy
108+ # these into production code. Keep them self‑contained and side‑effect free.
109+
110+ def _snyk_insecure_examples (user_input : str , sql_value : str , url : str , pickled : bytes ): # pragma: no cover
111+ """Insecure code samples to trigger SAST findings.
112+
113+ Patterns intentionally included:
114+ - Hardcoded credentials / secrets
115+ - Use of eval()
116+ - subprocess with shell=True (command injection risk)
117+ - Weak cryptographic hash (MD5)
118+ - SQL query string concatenation (SQL injection)
119+ - Unsafe deserialization via pickle.loads
120+ - HTTP request with TLS verification disabled (verify=False)
121+ """
122+ # Hardcoded secrets / credentials
123+ password = "P@ssw0rd!" # hardcoded password
124+ api_key = "AKIA1234567890FAKE" # fake AWS-style access key
125+
126+ # Dangerous dynamic evaluation
127+ eval ("print('Eval executed: ' + str(" + repr (user_input ) + "))" )
128+
129+ # Command injection risk via shell=True
130+ import subprocess
131+ subprocess .run (f"echo { user_input } " , shell = True )
132+
133+ # Weak hashing (MD5)
134+ import hashlib
135+ md5_digest = hashlib .md5 (user_input .encode ("utf-8" )).hexdigest ()
136+
137+ # SQL injection prone string building
138+ query = "SELECT * FROM users WHERE name = '" + sql_value + "'"
139+
140+ # Unsafe deserialization
141+ import pickle
142+ deserialized = pickle .loads (pickled )
143+
144+ # Insecure HTTP request (certificate verification disabled)
145+ import requests
146+ r = requests .get (url , verify = False )
147+
148+ return {
149+ "password" : password ,
150+ "api_key" : api_key ,
151+ "md5" : md5_digest ,
152+ "query" : query ,
153+ "deserialized" : deserialized ,
154+ "status" : r .status_code ,
155+ }
156+
157+
158+ # Guard to ensure the insecure examples never run during normal operation or tests
159+ if False : # pragma: no cover
160+ _snyk_insecure_examples (
161+ user_input = "example" ,
162+ sql_value = "alice" ,
163+ url = "http://example.com" ,
164+ pickled = b"\x80 \x04 \x95 \x02 \x00 \x00 \x00 \x00 \x00 \x00 \x00 }." , # benign small pickle for static analysis
165+ )
166+
102167 @post ("tables" , return_key = "id" )
103168 def create_table (self , table : models .CreateTableRequest ) -> str :
104169 """Create a new table with the provided metadata and column definitions.
0 commit comments