[DOCS][Dev] Add Security

This commit is contained in:
Diogo Peralta Cordeiro 2021-08-03 17:54:00 +01:00
parent 0273c8ca24
commit 7fd4149695
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 22 additions and 0 deletions

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