sqlshield 0.0.3__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sqlshield might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlshield
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: A Shield for your LLM generated SQL Queries. It provides an application level control for securing the database from SQL generated by LLM.
5
5
  Author-email: Sandeep Giri <sandeepgiri@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/terno-ai/llm-sql-shield
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sqlshield"
3
- version = "0.0.3"
3
+ version = "0.0.4"
4
4
  authors = [
5
5
  { name="Sandeep Giri", email="sandeepgiri@gmail.com" },
6
6
  ]
@@ -58,13 +58,15 @@ class MTable(Table):
58
58
  result.append("%s as %s" % (col.name, col.pub_name))
59
59
  return ', '.join(result)
60
60
 
61
- def get_alias_sql(self, params):
61
+ def get_alias_sql(self, params, alias=None):
62
62
  filterSQL = ''
63
63
  if self.filters:
64
64
  filterSQL = self.filters.format(**params)
65
65
  sql_template = '(select %s from %s %s) as %s'
66
66
  colsql = self._get_projections_sql()
67
- query = sql_template % (colsql, self.name, filterSQL, self.pub_name)
67
+ if alias == None:
68
+ alias = self.pub_name
69
+ query = sql_template % (colsql, self.name, filterSQL, alias)
68
70
  return query
69
71
 
70
72
  def generate_schema(self):
@@ -28,12 +28,16 @@ class Session():
28
28
 
29
29
  def transformer(node):
30
30
  if isinstance(node, exp.Table):
31
- tbl_name_c = node.this.this
31
+ tbl_name_c = node.this.this
32
32
  tbl_name = tbl_name_c.lower()
33
33
  if tbl_name not in tbl_map:
34
34
  raise Exception('No such table found.', tbl_name_c)
35
35
  mtable = tbl_map[tbl_name]
36
- msql = mtable.get_alias_sql(self.params)
36
+ if node.alias == '':
37
+ alias = None
38
+ else:
39
+ alias = node.alias
40
+ msql = mtable.get_alias_sql(self.params, alias)
37
41
  return parse_one(msql)
38
42
  return node
39
43
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlshield
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: A Shield for your LLM generated SQL Queries. It provides an application level control for securing the database from SQL generated by LLM.
5
5
  Author-email: Sandeep Giri <sandeepgiri@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/terno-ai/llm-sql-shield
@@ -17,7 +17,7 @@ def loadDb():
17
17
  return MDatabase.from_inspector(inspector)
18
18
 
19
19
  def build_protection(mDb):
20
- mDb.keep_only_tables(set(['Customer', 'Employee', 'Invoice', 'InvoiceLine']))
20
+ mDb.keep_only_tables(set(['Customer', 'Employee', 'Invoice', 'InvoiceLine', 'Album', 'Artist', 'Track']))
21
21
 
22
22
  tables = mDb.get_table_dict()
23
23
  print("Tables: ", tables)
@@ -39,6 +39,8 @@ if __name__ == "__main__":
39
39
  d = {'company':'\'Telus\''}
40
40
  sess = Session(mDb, d)
41
41
  sqls = [
42
+ "select t.name, al.title from track t join album al on t.AlbumId = al.AlbumId where name like '%Sex%';",
43
+ "select t.name, album.title from track t join album on t.AlbumId = album.AlbumId where name like '%Sex%';"
42
44
  'drop table t1;'
43
45
  'insert into Customers Values(1,2)',
44
46
  'create table t (age int)',
@@ -48,6 +50,7 @@ if __name__ == "__main__":
48
50
  'select * from Employee;drop table Employee;',
49
51
  'select * from cusTomers',
50
52
  'select * from cusTomer',
53
+
51
54
  ]
52
55
  for sql in sqls:
53
56
  try:
@@ -56,4 +59,3 @@ if __name__ == "__main__":
56
59
  print("Native SQL: ", gSQL)
57
60
  except Exception as e:
58
61
  print("ERROR: ", e.args)
59
-
File without changes
File without changes
File without changes