The Wayback Machine - https://web.archive.org/web/20200918102805/https://github.com/sqlkata/querybuilder/pull/303
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid SQL Injection in debug SQL #303

Open

Conversation

@freakingawesome
Copy link

freakingawesome commented Oct 8, 2019

I was happily making some other contributions to the codebase when I
decided to try testing for SQL Injection vulnerabilities. I was dismayed
when all my single quotes were not escaped in WHERE clauses and nearly
had a panic attack until I realized that the SQL validated in the
majority of these tests is just a debug mashup that includes parameter
bindings.

Nevertheless, I think it makes sense to escape single quotes properly
even in the debug SQL strings, if only to avoid giving some other
hapless maintainer a heart attack.

I was happily making some other contributions to the codebase when I
decided to try testing for SQL Injection vulnerabilities. I was dismayed
when all my single quotes were not escaped in WHERE clauses and nearly
had a panic attack until I realized that the SQL validated in the
majority of these tests is just a debug mashup that includes parameter
bindings.

Nevertheless, I think it makes sense to escape single quotes properly
even in the debug SQL strings, if only to avoid giving some other
hapless maintainer a heart attack.
@ahmad-moussawi
Copy link
Contributor

ahmad-moussawi commented Oct 22, 2019

Thank you for this contribution, but as you've said that the ToString() method should only be used for debugging purposes, sanitizing input would encourage developers to use it for execution, what I am actually thinking of is to force some warning string to be sent before the generated SQL to broke it.
something like:

--- UNSAFE SQL: SELECT * FROM [Table]
@freakingawesome
Copy link
Author

freakingawesome commented Oct 23, 2019

I think there is still value in sanitizing the debug SQL. I've used the debug string before to spot check problems quickly by copying and pasting into SQL Management Studio. Purposely leaving single quotes unescaped feels like an odd omission that will only cause confusion.

Prefixing the string with UNSAFE SQL: is informative, but I think a little misleading. It may be perfectly valid SQL, but the reality is that the SQL you see is only for debug purposes and not what is being sent to the database server. Perhaps the comment prefix could be broadened and separated by a newline from the actual SQL? Something like,

-- Warning: This SQL is for debugging purposes only. Learn more at https://sometiny.url
SELECT * FROM [Table]
@ahmad-moussawi ahmad-moussawi force-pushed the sqlkata:master branch 6 times, most recently from f9a6417 to a30bb49 Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.