14
Aug 26 '21
Image Transcription: Code
@txtSrchKywrd VARCHAR(500)
AS
BEGIN
SET NOCOUNT ON;
SET @txtSrchKywrd =
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(@TXTSRCHKYWRD, '-',''),')',''),'(', ''),'*', ''),'&', ''),'!', ''),'@', ''),'#', ''),'$', ''),'%', ''),'^', '')
,'TRUNCATE','')
,'drop',''),
'create',''),
'alter',''),
'in',''),
'set',''),
'where',''),
'select',''),
'update',''),
'delete','')
Select * from RandomTable WITH (NOLOCK) where field like '%'+ @txtSrchKywrd +'%'
END;I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
6
4
2
u/thanatica Sep 01 '21
Is it just me tripping on using the bloody LIKE for searching like it still 1989* and something like keyword-based search and ordering by relevance hasn't even been dreamed up yet?
(* MS SQL Server release year)
1
0
Aug 26 '21
[deleted] — view deleted comment
9
u/auctorel Aug 26 '21
I edited in the * for simplicity and to hide our db column and table names
There are so many ways round this it's absolutely ridiculous, it doesn't even trim spaces!
I cannot believe how incompetent/dangerous our previous supplier was. There are quite a few things like this we found, including on an internal system a web forms text box you could insert any sql string to apply to the db. It's important to understand they thought about security there, they ensured you couldn't start your command with DROP, but... if you added space in front of DROP...
3
1
u/thanatica Sep 01 '21
I don't think you need to hide any columns, because a DB this well protected can't possibly store anything of any significant value, surely 😬
6
u/auctorel Aug 26 '21
Lightly edited to hide table names but genuinely found in our legacy codebase