Junior — Middle
What tools and technologies do you use to ensure system security against potential cyber threats?
sobes.tech AI
Answer from AI
To ensure the security of Python applications, I use several approaches and technologies:
- Authentication and authorization: libraries like
Djangowith built-in authentication system,Flask-Loginfor Flask. - Data encryption: the
cryptographymodule for symmetric and asymmetric encryption. - Input validation and sanitization: using libraries like
pydanticormarshmallowfor data validation. - Protection against SQL injection: using ORM (e.g., SQLAlchemy) and parameterized queries.
- Dependency updates: regularly updating libraries and using
pip-auditto find vulnerabilities. - Logging and monitoring: setting up logs with
loggingand integrating with monitoring systems.
Example of using cryptography for encrypting a string:
from cryptography.fernet import Fernet
key = Fernet.generate_key()
cipher_suite = Fernet(key)
text = b"secret message"
cipher_text = cipher_suite.encrypt(text)
plain_text = cipher_suite.decrypt(cipher_text)
print(plain_text.decode())