Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. The Practices That Actually Matter
Python & Django

The Practices That Actually Matter

Security for Python services: validating input at the boundary, keeping secrets out of code, auditing dependencies and enforcing authorisation server-side.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Validate input at the boundary, keep secrets out of code, audit dependencies automatically, and enforce authorisation server-side on every action.

Validate at the boundary

Every piece of external data — request bodies, file contents, API responses, queue messages — should be validated into a known shape before any logic touches it.

A service that validates at the boundary can trust its internals. One that validates ad hoc is where the subtle failures live.

Secrets

  1. Never in the repository, including in history
  2. Environment variables at minimum, a secrets manager where available
  3. Different per environment, so staging cannot touch production
  4. Rotatable, and actually rotated
  5. Never logged, including in error handlers

Secrets committed to a repository remain in the history after deletion. Rotate them rather than assuming removal was sufficient.

Dependencies

  • Automated vulnerability auditing on every build
  • Security updates applied within days
  • A lock file, so builds are reproducible
  • Awareness of what each dependency pulls in transitively
  • Fewer dependencies where a small amount of code would do

Authorisation on every action

CheckWhere
Is the caller authenticated?At the boundary
May they perform this action?In the handler
May they access this record?In the query
Is the input within their scope?Before acting
Was it logged?After acting

The most common authorisation failure is checking the action but not the record — a user permitted to view orders viewing someone else's.

Deserialisation and code execution

Never deserialise untrusted data with formats that can execute code, and never pass user input to anything that evaluates it. Both are straightforward to avoid and catastrophic when present.

Use safe data formats, and validate their contents rather than trusting their structure.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

How do we audit dependencies?

An automated tool in the build pipeline. Manual checking does not happen consistently.

What if a secret was committed?

Rotate it. Removing the commit does not remove it from history or from anywhere the repository was cloned.

Should we scan uploaded files?

Where files will be shared with other users, yes. Store them outside any web-accessible path regardless.

How often should we review security?

Dependencies continuously and automatically. A broader review annually or after any significant change.

Keep reading

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

Never audited a Python service for these?

The four areas above cover most practical risk. Happy to review what you are running.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →