[DOCS][Dev] Add Security

This commit is contained in:
Diogo Peralta Cordeiro 2021-08-03 17:54:00 +01:00 committed by Hugo Sales
parent 367cc5c5c7
commit c99e447308
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -0,0 +1,22 @@
# Security
## Validate vs Sanitize
You're probably already familiar with the old saying "Never trust your users
input", if not, you're now.
Sadly, that often worries developers so much that they will _sanitize_ every
single user input before storing it. That's, to our eyes, a bad practice.
You shouldn't trust your users, but that should never lead you to break [data integrity](https://en.wikipedia.org/wiki/Data_integrity).
Instead of sanitize before store, you should _validate_ if the input makes sense,
and tell your client if it isn't.
## Sanitize before spitting out
If a user inputs a string containing HTML tags, you shouldn't strip them out
before storing. Depending on the context, you should sanitize it before
outputting. For that you can call `App\Core\Security::sanitize(string: $html)`,
optionally you can send a second argument specifying tags to maintain `array: ['tag']`.
## Generating a readable confirmation code
TODO