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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:14:54+00:00 2026-05-20T05:14:54+00:00

I am developping an ASP2.0 website with a Microsoft SQL server 2005 Database. I

  • 0

I am developping an ASP2.0 website with a Microsoft SQL server 2005 Database.
I need to implement a functionality which allows users to create a select query (nothing too complex) so that the website displays a page with the result set of the query.
My question is how can I sanitize the query to make sure there is no insert/update/delete/drop or other nefarious injection.

also, I need to encapsulate the query in a “with” clause so that I can add an identity column to the result set. (I need that to display the results correctly on the page)

my CSharp code to format the query looks like this (simplified a little):

string query = txtQuery.Text;
query = query.ToLower();
query = query.Trim();
int orderByIndex = query.LastIndexOf("order by");
string orderBy = "";
if (orderByIndex != -1)
{
    orderBy = query.Substring(orderByIndex);
    query = query.Replace(orderBy, "");
}
query = "with query as (" + query + ") select row_number() over(order by (select 0)) as rowID, * from query " + orderBy;

I want to create a stored procedure to execute the query. I was thinking of something like this:

CREATE PROCEDURE usp_execute_query
@sql nvarchar(max)
with execute as 'RestrictedUser'
as
begin
    exec sp_executesql @sql
end

with RestrictedUser looking like this:

CREATE USER RestrictedUser WITHOUT LOGIN
EXEC sp_addrolemember db_datareader, RestrictedUser

My questions are:
Is there a way to check the roles of RestrictedUser within the stored procedure to make sure they haven’t been tampered? And raiserror if they have.
Do you think this whole thing is the right way to go? Any suggestion?

  • 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-05-20T05:14:55+00:00Added an answer on May 20, 2026 at 5:14 am

    Danger Will Robinson! Any time you’re allowing a user to pass arbitrary SQL, you’re running into all sorts of security issues. The odds of you plugging every hole are slim. Plus, the ability to “sanitize” a query is predicated on your ability to parse the query. It is possible to parse SQL yourself, but it’s not trivial by any stretch of the imagination. Also, because this is a web app, you’re pitting your skills against a lot of people with probably more experience performing sql injection attacks.

    Creating the user with very limited permissions is a good thing (and likely your best shot). However, you will need to be fastidious about what they have access to (system stored procs, system views, etc). In other words, db_datareader is not limited enough. You’ll want to create an entirely new rule and only given them permission to very specific items.

    Keep in mind that even though you might succeed in limiting what pieces of data the user (aka hacker in this scenario) can see, you’re still vulnerable to DOS (Denial of Service) attacks.

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

Sidebar

Related Questions

I'm developping an Android app which uses the same MySQL server as a website
I'm developping app using java, c3p0 for connection pooling and SQL Server 2005 for
I am developping a BlackBerry application which communicates with the server via HTTP requests(
I'm currently developping an Android application which connects to a server through TCP. The
I'm currently developping a Chrome extension (which means that I don't need a cross
I'm developping a server application in Java. The server need two type of server
I am developping an application which aggregates feeds. These feeds are on a server
I am developping an Android app, and I need to encode and decode a
I'm currently developping a search engine using Solr for an ecommerce website. So I
I'm developping a web app and I need encrypt strings in javascript to compare

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.