Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Insert into mysql database

by NorCal12 (Novice)
on Mar 03, 2021 at 00:11 UTC ( [id://11129042]=note: print w/replies, xml ) Need Help??


in reply to Insert into mysql database

Thanks for your comments. I ran things with your suggested language and it flagged the issue. Most sales involve pounds of quota, but when one sells fishing gear for example, there are no pounds. In that case the pounds field went into the database as null. All of my tests were using fishing gear and the newer version of mysql was not as forgiving as the older version. But at least I now know what needs to be done.

As far as using PHP on the site, I do use it on some presentation tables displaying past sales. But for my current issue that is not involved.

Replies are listed 'Best First'.
Re^2: Insert into mysql database
by Radiola (Monk) on Mar 03, 2021 at 02:02 UTC

    In case it’s not clear from the references to placeholders and Little Bobby Tables, the way your query works is very dangerous. Someone who knows what they’re doing could cause your database to run their SQL statements with the privileges of your CGI program.

    The problem is that the backslash escaping doesn’t escape everything — in particular, not the input from the form. If an attacker doctored up a form submission so that it included their own SQL in the right place, and fixed up the front and back of that string so that the whole combination of your SQL query plus whatever they submitted in $form{'ITEM'} still resulted in a valid series of SQL statements, your DB will cheerfully run the whole thing. An attacker could potentially steal customers’ private data, submit bogus transactions, or clear the whole database.

    It’s error-prone at best to pre-process $form{'ITEM'} to escape or strip stuff like that. The placeholders that hippo and LanX refer to solve the problem by telling the DB that your data is only data and not to run it no matter what it looks like.

    You really need to do this, especially if you’re dealing with money. It might be some work now, but it will correct a very dangerous problem, and your code will likely end up easier to read (and write) to boot.


    – Aaron
    Preliminary operational tests were inconclusive. (The damn thing blew up.)
Re^2: Insert into mysql database
by LanX (Saint) on Mar 03, 2021 at 00:28 UTC
    > But at least I now know what needs to be done.

    I hope you know that using SQL-placeholders are the easiest, most robust and safest solution.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129042]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found