Skip to content

Commit 5c05239

Browse files
authored
Create SQLInjection.cls
1 parent 0d5ef76 commit 5c05239

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

SQLInjection.cls

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Class User.SQLInjection
2+
{
3+
4+
// Some simple functions to sanitize different parts of a query
5+
6+
/// Scrubs a string of harmful characters, and any extra characters we pass
7+
ClassMethod SQLiHandlerValue(pQueryString, pOptional As %String = "") As %String
8+
{
9+
set pQueryString = $replace(pQueryString,"SELECT","ILLEGALVALUE")
10+
set pQueryString = $replace(pQueryString,"select","ILLEGALVALUE")
11+
// Removes anything that isn't a letter, number, whitespace
12+
return $zstrip(pQueryString,"*E'A'N'W",,pOptional)
13+
}
14+
15+
/// Scrubs a string of everything but numerical characters, and any extra characters we pass
16+
ClassMethod SQLiHandlerNumber(pQueryString, pOptional As %String = "") As %String
17+
{
18+
// Removes anything that isn't a number
19+
return $zstrip(pQueryString,"*E'N",,pOptional)
20+
}
21+
22+
/// Takes in a field name and checks it in a table of safe values. Helpful if the user needs rights to the field but only when we want
23+
ClassMethod SQLiHandlerKey(pQueryString) As %String
24+
{
25+
set acceptableList = ["some","fieldname"]
26+
set iter = acceptableList.%GetIterator()
27+
set outputKey = "ILLEGALVALUE"
28+
while iter.%GetNext(.key, .value) {
29+
if pQueryString = value set outputKey = value
30+
}
31+
return outputKey
32+
}
33+
34+
}

0 commit comments

Comments
 (0)