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 87585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:25:33+00:00 2026-05-10T22:25:33+00:00

I am taking in a string from user input, and splitting it on whitespace

  • 0

I am taking in a string from user input, and splitting it on whitespace (using \w) into an array of strings. I then loop through the array, and append a part of the where clause like this:

            query += ' AND ( '                   + 'field1 LIKE '%' + searchStrings[i] +'%' '                  + ' OR field2 LIKE '%' + searchStrings[i] +'%' '                  + ' OR field3 LIKE '%' + searchStrings[i] +'%' '                  + ') '; 

I feel like this is dangerous, since I am appending user input to my query. However, I know that there isn’t any whitespace in any of the search strings, since I split the initial input on whitespace.

Is it possible to attack this via a SQL injection? Giving Robert');DROP TABLE students;-- wouldn’t actually drop anything, since there needs to be whitespace in there. In that example, it would not behave properly, but no damage would be done.

Can anyone with more experience fighting SQL injections help me either fix this, or put my mind at ease?

Thanks!

EDIT:

Wow, that is a lot of great input. Thank you everyone who responded. I will investigate full-text search and, at a minimum, parameterize my query.

Just so I can better understand the problem, would it be possible to inject if all whitespace AND single quotes were escaped?

  • 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-10T22:25:34+00:00Added an answer on May 10, 2026 at 10:25 pm

    Any time you allow a user to enter data into a query string like this you are vulnerable to SQL injection and it should be avoided like the plague!

    You should be very careful how you allow your searchStrings[] array to be populated. You should always append variable data to your query using parameter objects:

    + field1 like @PropertyVal Or field2 like @PropertyVal Or field3 like @PropertyVal etc... 

    And if you’re using SQL Server for example

    Query.Parameters.Add(new SqlParameter('PropertyVal', '%' + searchStrings[i] + '%')); 

    Be very wary how you build a query string that you’re going to run against a production server, especially if it has any data of consequence in it!

    In your example you mentioned Little Bobby Tables

    Robert’);DROP TABLE students;–

    And cited that because it needs white space, you couldn’t do it – but if the malicious user encoded it using something like this:

    Robert');Exec(Replace('Drop_Table_students','_',Char(32)));-- 

    I would say – better to be safe and do it the right way. There’s no simple way to make sure you catch every scenario otherwise…

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • 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 Use URI routing to override the default controller/function/arguments mapping. Example:… May 11, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer You can determine the status of the fulltext indexing by… May 11, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer If you mean a python script, just do something like… May 11, 2026 at 11:33 pm

Related Questions

I am taking an input string from a user and using that as the
I am a C++ user and now trying to use c#. In c++ taking
I am working on a function that takes in a series of permission strings,
I'm using ActiveRecord to maintain information about users. The User class has the expected

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.