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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:19:32+00:00 2026-05-27T00:19:32+00:00

A get request is issued to a php page. One of the key/value pairs

  • 0

A get request is issued to a php page. One of the key/value pairs is passed to this function, getReport, which accesses the mysql database and returns a json-serialized string:

function getReport($untrusted) {
    $tables = array(
        "day"        => "p_day", 
        "month"      => "p_month"
        ... keys are 'untrusted', values are 'trusted' table names .....
    );

    $trusted = $tables[$untrusted];
    if(!$trusted) {
        ... error out ...
    }

    $query = "select * from " . $trusted;

    .... access mysql database, do some other stuff ...
}

The question: is this secure? The untrusted input is only used as a lookup to get a trusted string. The trusted string is used to build a query.


Clarification:

the data is publicly available. I’m worried about SQL injection, or the user getting access to the connection parameters or to a table that isn’t explicitly listed in $tables.

  • 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-27T00:19:32+00:00Added an answer on May 27, 2026 at 12:19 am

    I describe a similar method in my presentation SQL Injection Myths and Fallacies, and in my book SQL Antipatterns Volume 1: Avoiding the Pitfalls of Database Programming. I called it Whitelist Maps but the idea is the same.

    In my example, I use array_key_exists() because if you try to access a hash key that doesn’t exist you’ll get an error. Also if the key doesn’t exist, in my example I choose a default instead of erroring out. But that’s up to you, and either action may be the right thing depending on the application requirements.

    You should also restrict the hash to just the list of tables you want to be accessed by a given web request. Don’t just let any URL query any table in your database just because they get the name right. This means you need to create a different hash array for each instance where user input determines an SQL identifier (table or column name, etc.).

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

Sidebar

Related Questions

I make an AJAX GET request to a PHP script to compare a value
A simple get request made to url on my server which returns HTML of
I'm trying to get request params passed by PUT request, at Grails-based app. I'm
I'm doing a $.get() request which returns some HTML. I would like to manipulate
Issue: I have a Mootools Request object which sends a GET request to a
This is what I want - When somebody enters site.com/page.php or site.com/page or site.com/page/
When I try to use ['signed_request'] in PHP, I can't get [page][liked] / Page
I have a GET request in a document. The current page I am on
This is the page, its a wordpress powered site: http://bit.ly/9oJXWV You select some value,
Doing an ajax get request works as expected using the following code: $.ajax({ type:

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.