If this is your first visit, check our documentation. To post, register or login.
Forums / Code Collaboration / Security Measures Best Practice for Proceesing Form inputs

Security Measures Best Practice for Proceesing Form inputs

Started by dave224 on 4 Sep 2020, 3:38 PM · Views: 2,233

Results 1 to 9 of 9
4 Sep 2020, 3:38 PM
#1
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Security Measures Best Practice for Proceesing Form inputs

I have a custom form seeking name, address, phone number and several other parameters. What ZC security functions should be used to protect the database and code against spam and other forms of attack?
Thanks,
Dave

zc155f, many add-ons and custom code, php 7.1.x

4 Sep 2020, 4:19 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Security Measures Best Practice for Proceesing Form inputs

Seeking the information may not be as much of an issue as what is done with or what is returned as a result of processing the provided information, though all such avenues are important to consider/address.

For one, there is the zen_draw_form function which intends to link the provided information to the session to validate that the information was provided from the site and not an external source. There is the use of 'post' as the method of communication. There is the use of a SSL. There is sanitization of the data that has been provided (if something is expected to be an integer, then cast the data to an integer). There is data validation (if area being served has a zip code and the zip code can only be made of numbers, then prevent undesirable characters from being included in the data). Before using user entered data to access the database, be sure to sanitize it noting that there are some things/entries that could use the word 'null' either in all lowercase or all uppercase or perhaps entered as a mix and be sure to handle such entry as expected/desired.

Generally speaking, if entry of the information is to evoke a response based on "proper" entry then false/incorrect entries of any portion of the data should return the same response as a false entry of any other part of the data otherwise brute force techniques are easier to complete. E.g. if a user were to enter a login name with an incorrect password then identifying that the only issue is the password positively identifies the login name is correct and only the password needs to be discovered. Instead the recommendation generally is to identify that there is a problem with the combination which would also be output if the username was incorrect but a correct password for someone were entered.

Potentially have the individual be logged in to enter the data (limits attempts to those that have gotten past the login process).

These I think are many ways to at least make a basic effort to safely/securely collect the information.

Would recommend further description of "plans" to get more specific recommendations.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

4 Sep 2020, 5:16 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Re: Security Measures Best Practice for Proceesing Form inputs

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

4 Sep 2020, 6:51 PM
#4
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Security Measures Best Practice for Proceesing Form inputs

mc12345678,
summarizing your suggestions:
zen_draw_form - yes
$_POST - yes
SSL - yes
sanitization - yes, using zen_db_prepare_input; no (not yet) cast integers
data validation - yes
null treatment - no
logged-in - yes

Plans are to store data in database new table and process later using phpMyAdmin

Questions: Is zen_db_prepare_input sufficient sanitization? Should I and can I use admin sanitization on store side? Do you mean by null treatment that every entry should be checked for any form of null and flag error if found i.e, part of data validation?

Thanks for your advice and hope to see answers to my questions when you can.
Dave

5 Sep 2020, 12:30 AM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Security Measures Best Practice for Proceesing Form inputs

Instead of zen_db_prepare_input, which despite its name is not fit for storing to db; use zen_db_input() ... or use $db->bindVars() and cast to specific type.
No, the admin sanitization stuff doesn't work catalog-side.

https://docs.zen-cart.com/dev/code/database_querying

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

5 Sep 2020, 2:19 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Security Measures Best Practice for Proceesing Form inputs

Do you mean by null treatment that every entry should be checked for any form of null and flag error if found i.e, part of data validation?

One of the "articles" that I've come across either as a reference by a poster here or some sort of research was that it is possible that someones real last name is Null and as such, they should be permitted to type that in and it not get stored "oddly". In recent versions of Zen Cart there has been a data type that supports allowing entering a name such as that: stringIgnoreNull. Otherwise, if you use the bindVars method to cast a variable to a string, depending on the version if the string contains 'null' or 'NULL' then the entire string basically becomes the SQL equivalent of null regardless of how much content there is.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

5 Sep 2020, 6:28 AM
#7
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Re: Security Measures Best Practice for Proceesing Form inputs

That has got to be an XKCD cartoon. Like Little Bobby Tables.

https://xkcd.com/327/

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

5 Sep 2020, 3:09 PM
#8
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Security Measures Best Practice for Proceesing Form inputs

:laugh::laugh: Hilarious!

5 Sep 2020, 6:40 PM
#9
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,760
Plugin Contributions:
56

Re: Security Measures Best Practice for Proceesing Form inputs

There was a story about a wise guy who got NULL for his license plate and it had the opposite of the intended effect.

https://www.wired.com/story/null-license-plate-landed-one-hacker-ticket-hell/

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.