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

  • SEARCH
  • Home
  • 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 8508413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:09:16+00:00 2026-06-11T03:09:16+00:00

Possible Duplicate: Can I protect against SQL Injection by escaping single-quote and surrounding user

  • 0

Possible Duplicate:
Can I protect against SQL Injection by escaping single-quote and surrounding user input with single-quotes?

I just want to know, If I replace every ' with '' in user inputs, for instance string.Replace("'","''"), and validate numbers (make sure that they are numbers, and do not contain any other character), is SQL Injection still possible? How?

I’m using dynamic SQL queries, using SqlCommand. Something like this:

cmd.CommandText = "SELECT * FROM myTable WHERE ID = " + theID.ToString();

or

cmd.CommandText = "UPDATE myTable SET title='" + title.Replace("'","''") + "' WHERE ID = " + theID.ToString();

Input integers are automatically validated (checked whether they are a real number) in ASP.NET MVC.

  • 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. Editorial Team
    Editorial Team
    2026-06-11T03:09:18+00:00Added an answer on June 11, 2026 at 3:09 am

    If this is a legacy project that is coded this way then, whilst not optimal, I’m not currently aware of any way that it can be susceptible to SQL injection as long as every string is treated in that manner and the queries are just simple ones as you have shown.

    I cannot state any more certainty than that however. Without using parametrised queries there is always the possibility that there is some vulnerability that you have not yet considered.

    Manually escaping the quotes yourself is error prone and can sometimes fail in ways that are difficult to anticipate in advance. For example with the following table

    CREATE TABLE myTable(title VARCHAR(100))
    INSERT INTO myTable VALUES('Foo')
    

    And stored procedure using dynamic SQL built up with string concatenation

    CREATE PROC UpdateMyTable
    @newtitle NVARCHAR(100)
    AS
    /*
    Double up any single quotes
    */
    SET @newtitle = REPLACE(@newtitle, '''','''''')
    
    DECLARE @UpdateStatement VARCHAR(MAX)
    
    SET @UpdateStatement = 'UPDATE myTable SET title='''  + @newtitle + ''''
    
    EXEC(@UpdateStatement)
    

    You can try the following

    Normal update

    EXEC UpdateMyTable N'Foo'
    SELECT * FROM myTable /*Returns "Foo"*/
    

    SQL Injection attempt foiled

    EXEC UpdateMyTable N''';DROP TABLE myTable--'
    SELECT * FROM myTable  /*Returns "';DROP TABLE myTable--"*/
    

    SQL Injection attempt succeeds and drops the table

    EXEC UpdateMyTable N'ʼ;DROP TABLE myTable--'
    SELECT * FROM myTable  /*Returns "Invalid object name 'myTable'."*/
    

    The issue here is that the third query passes U+02BC instead of the standard apostrophe and then the string is assigned to a varchar(max) after the sanitation occurs which silently converts this to a regular apostrophe.

    Until I read the answer here that issue would never have occurred to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I protect against SQL Injection by escaping single-quote and surrounding user
Possible Duplicate: How prepared statements can protect from SQL injection attacks? If I'm using
Possible Duplicate: How to protect my source code when deployed? Can you give me
Possible Duplicate: Where can I find a web-project “security checklist?” i was just wondering
Possible Duplicate: Can I use pure SQL in ASP.net MVC? i asked a similar
Possible Duplicate: Can't run a ruby hello world application in Aptana I've just installed
Possible Duplicate: .NET windows application, can it be compressed into a single .exe? I
Possible Duplicate: .NET windows application, can it be compressed into a single .exe? I
Possible Duplicate: Best way to stop SQL Injection in PHP I'd like a simple
Possible Duplicate: Classic ASP SQL Injection Protection So far, I've been very lucky not

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.