Bad actors are there. We need to be very careful with their input.
TL;DR: Sanitize everything that comes from outside your control.
- Use sanitization and input filtering techniques.
Whenever you get input from an external resource, a security principle requests you to validate and check for potentially harmful inputs.
SQL Injection is a notable example of a threat.
We can also add assertions and invariants to our inputs.
Even better, we can work with Domain Restricted Objects.
user_input = "abc123!@#" # This content might not be very safe if we expect just alphanumeric characters
import re def sanitize(string): # Remove any characters that are not letters or numbers sanitized_string = re.sub(r'[^a-zA-Z0-9]', '', string) return sanitized_string user_input = "abc123!@#" print(sanitize(user_input)) # Output: "abc123"
We can statically check all the inputs and also we can also use penetration testing tools.
We need to be very cautious with the inputs beyond our control.
Code Smell 178 - Subsets Violation
Maxi Contieri ⭐⭐⭐ ・ Nov 10 ・ 2 min read
Code Smell 15 - Missed Preconditions
Maxi Contieri ⭐⭐⭐ ・ Nov 3 '20 ・ 2 min read
Code Smells are just my opinion.
Photo by Jess Zoerb on Unsplash
Companies should make their own enterprise systems as often as network security companies should manufacture their own aspirin.
Software Engineering Great Quotes
Maxi Contieri ⭐⭐⭐ ・ Dec 28 '20 ・ 13 min read
This article is part of the CodeSmell Series.
Top comments (2)
Sanitisation can get quite complex when you're stripping invalid characters, but you need to allow users to enter things that aren't in English. By which I guess I mean, don't roll your own, use an existing library for it.
yes. the example is a simple case just to illustrate the concept, as usual