Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 49637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:28:05+00:00 2026-05-10T16:28:05+00:00

I realize that parameterized SQL queries is the optimal way to sanitize user input

  • 0

I realize that parameterized SQL queries is the optimal way to sanitize user input when building queries that contain user input, but I’m wondering what is wrong with taking user input and escaping any single quotes and surrounding the whole string with single quotes. Here’s the code:

sSanitizedInput = ''' & Replace(sInput, ''', '''') & ''' 

Any single-quote the user enters is replaced with double single-quotes, which eliminates the users ability to end the string, so anything else they may type, such as semicolons, percent signs, etc., will all be part of the string and not actually executed as part of the command.

We are using Microsoft SQL Server 2000, for which I believe the single-quote is the only string delimiter and the only way to escape the string delimiter, so there is no way to execute anything the user types in.

I don’t see any way to launch an SQL injection attack against this, but I realize that if this were as bulletproof as it seems to me someone else would have thought of it already and it would be common practice.

What’s wrong with this code? Is there a way to get an SQL injection attack past this sanitization technique? Sample user input that exploits this technique would be very helpful.


UPDATE:

I still don’t know of any way to effectively launch a SQL injection attack against this code. A few people suggested that a backslash would escape one single-quote and leave the other to end the string so that the rest of the string would be executed as part of the SQL command, and I realize that this method would work to inject SQL into a MySQL database, but in SQL Server 2000 the only way (that I’ve been able to find) to escape a single-quote is with another single-quote; backslashes won’t do it.

And unless there is a way to stop the escaping of the single-quote, none of the rest of the user input will be executed because it will all be taken as one contiguous string.

I understand that there are better ways to sanitize input, but I’m really more interested in learning why the method I provided above won’t work. If anyone knows of any specific way to mount a SQL injection attack against this sanitization method I would love to see it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:28:05+00:00Added an answer on May 10, 2026 at 4:28 pm

    First of all, it’s just bad practice. Input validation is always necessary, but it’s also always iffy.
    Worse yet, blacklist validation is always problematic, it’s much better to explicitly and strictly define what values/formats you accept. Admittedly, this is not always possible – but to some extent it must always be done.
    Some research papers on the subject:

    • http://www.imperva.com/docs/WP_SQL_Injection_Protection_LK.pdf
    • http://www.it-docs.net/ddata/4954.pdf (Disclosure, this last one was mine 😉 )
    • https://www.owasp.org/images/d/d4/OWASP_IL_2007_SQL_Smuggling.pdf (based on the previous paper, which is no longer available)

    Point is, any blacklist you do (and too-permissive whitelists) can be bypassed. The last link to my paper shows situations where even quote escaping can be bypassed.

    Even if these situations do not apply to you, it’s still a bad idea. Moreover, unless your app is trivially small, you’re going to have to deal with maintenance, and maybe a certain amount of governance: how do you ensure that its done right, everywhere all the time?

    The proper way to do it:

    • Whitelist validation: type, length, format or accepted values
    • If you want to blacklist, go right ahead. Quote escaping is good, but within context of the other mitigations.
    • Use Command and Parameter objects, to preparse and validate
    • Call parameterized queries only.
    • Better yet, use Stored Procedures exclusively.
    • Avoid using dynamic SQL, and dont use string concatenation to build queries.
    • If using SPs, you can also limit permissions in the database to executing the needed SPs only, and not access tables directly.
    • you can also easily verify that the entire codebase only accesses the DB through SPs…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I see the hackish way only: post your file as… May 11, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer The preferences for each individual widget and the dashboard itself… May 11, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer you can just copy and paste the innerhtml. var data… May 11, 2026 at 11:50 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a mostly desktop programming background. In my spare time I dabble in
I've written a C++ matrix template class. It's parameterized by its dimensions and by
I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.