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 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 am developping a (relatively small) website in ASP.Net 2.0. I am also using
I am developping in C#. I need to capture a password written inside a
I am developping a Cocoa application and I have a special need. In my
I'm developping a small UML Class editor in Java, mainly a personal project, it
I'm currently developping an application in java using Hibernate as a persistence manager and
In the application I'm developping (in Java/swing), I have to show a full screen
A lot of times when reading about web developping on the internet I hear
Developing a website and just trying to get back into the swing of (clever)
i'm developping an application in CF 3.5 for windows Mobile 6 Pro using C#
I am developping on Windows with DevStudio, in C/C++ unmanaged. I want to allocate

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.