Courses / Web apps & analytics / Secure Coding Fundamentals

Free courseSelf-paced

Secure Coding Fundamentals

Find and fix common security flaws in Python code, from input handling and secrets to authorization and race conditions, and prove each fix with tests.

  • Who it's for. Programmers with basic Python and networking knowledge who want to write code that resists common attacks.
  • Before you start. Courses: Programming Problem Solving, Networking Fundamentals. Prerequisite courses Programming Problem Solving and Networking Fundamentals.
  • 30 to 54 hours of study with practice
  • 10 modules, 54 lessons
  • 4 guided projects and a final project

What you'll learn

  • Identify untrusted sources and sensitive sinks in code and apply least privilege, secure defaults, small attack surface and layered controls
  • Parse input into typed values, canonicalise before validating, bound regular expressions, encode output per context and avoid unsafe deserialisation
  • Explain memory-safety bug classes and unsafe-language pitfalls using runnable pure-Python models and choose safe abstractions
  • Keep secrets out of source and output and load configuration that fails closed
  • Choose the right cryptographic primitive, use secrets, HMAC and Fernet through library APIs and recognise home-made cryptography

Skills you'll gain

  • Trust boundaries
  • secure design principles
  • Input
  • output handling in Python
  • Memory safety
  • unsafe-language pitfalls
  • Secrets
  • configuration in code
  • Cryptography use
  • authentication primitives
  • Authorization decisions
  • concurrency pitfalls
  • Secure error handling
  • data privacy in code

Tools you'll use

  • Python
  • unittest
  • hmac
  • hashlib
  • secrets
  • Bandit

Details to know

  • Certificate on completionIssued after your final project is reviewed
  • 10 module checkpointsA quiz and a practical task close each module
  • Self-pacedStudy any time; your progress is saved

How every lesson works

Each lesson follows the same four steps, so you always know what comes next.

  1. 01

    Watch & Learn

    A short animated video explains one idea at a time.

  2. 02

    Guided Practice

    Work through an example step by step and check the result.

  3. 03

    Quiz & Challenge

    Short questions check the idea has landed before you move on.

  4. 04

    Mini Project

    Build something useful from a project brief.

Learn at your own pace

This is a self-paced course. There are no live classes and no fixed timetable.

  • Start any timeStudy when it suits you. Lessons are short, so they fit around work or college.
  • Pick up where you left offYour progress is saved to your account.
  • Ask when you're stuckUse Ask Mentor inside the learning platform.

Your path in 5 phases

Each phase ends with something you have built and checked.

  1. 01

    Modules 1 to 3

    Boundary and input core of Clinicdesk

    Covers Trust boundaries and secure design principles, Input and output handling in Python and Memory safety and unsafe-language pitfalls.

    You build: Guided project: taint.md, narrowed read-only reporting, fail-closed access, surface test and layered booking limits.

  2. 02

    Modules 4 to 5

    Secrets, configuration and cryptography layer

    Covers Secrets and configuration in code and Cryptography use and authentication primitives.

    You build: Guided project: Environment-loaded credentials, typed fail-closed config, Secret wrapper, canary helper and merged settings with redacted dump.

  3. 03

    Modules 6 to 7

    Authorization, state and privacy layer

    Covers Authorization decisions and concurrency pitfalls and Secure error handling and data privacy in code.

    You build: Guided project: Default-deny authorization function enforced at the action, locked counters, atomic SQL updates and exclusive file creation.

  4. 04

    Modules 8 to 9

    Static analysis and review pack

    Covers Unsafe APIs, dependencies and static analysis and Vulnerability patterns and secure code review.

    You build: Guided project: Dependency adapter, unsafe-call replacements, Bandit report, triage record, before and after comparison and the logic-flaw test.

  5. 05

    Module 10

    Final project and assessment

    Covers Defensive coding project, then the final project: Threat-reviewed application feature with defensive tests.

    You build: Final project, one of: Share-link feature for the Clinicdesk starter: expiring signed visit-summary links with authorization, allow-listed output.

Full curriculum

10 modules and 54 lessons, 30 to 54 hours of study

01Trust boundaries and secure design principles5 lessons, 2 to 4 hours

Lessons

  • Label sources and sinks in a short script
  • Narrow what a function can touch with least privilege
  • Make the safe choice the default and fail closed
  • Delete unused entry points to shrink attack surface
  • Layer two independent controls and test each alone

After this module you can

  • Classify every input source and every sensitive sink in a 40-line Python script and mark each place where an untrusted value reaches a sink unchecked.
  • Rewrite a function so it receives only the capability it needs, a read-only database connection or a single directory handle, and show by test that a write attempt is refused.
  • Implement an input check and a separate downstream guard for the same risk and write tests proving each layer blocks the probe when the other is disabled.
02Input and output handling in Python6 lessons, 3 to 4 hours

Lessons

  • Parse text into a typed value once, at the boundary
  • Reject out-of-range numbers and the bool-is-int trap
  • Canonicalise before you validate
  • Anchor patterns and bound length before matching
  • Encode output for the context it lands in
  • Refuse to unpickle untrusted bytes and verify integrity of stored blobs

After this module you can

  • Write a constructor that accepts raw strings and returns an immutable validated object or raises ValueError, so the rest of the program never sees unchecked text.
  • Validate a numeric quantity for type, finiteness and range, and show with tests that True, NaN, inf and negative values are refused.
  • Replace pickle.loads on received bytes with json.loads plus schema checks and, where a stored blob must be tamper-evident, verify an HMAC tag before parsing.
03Memory safety and unsafe-language pitfalls5 lessons, 2 to 4 hours

Lessons

  • Name the memory-safety bug classes in annotated snippets
  • Model a bounded buffer and make writes check their limits
  • Catch integer wraparound before it sizes an allocation
  • Model a use-after-free and fix it with generation counters
  • Choose safe abstractions and keep unsafe code small

After this module you can

  • Classify six short annotated C-style snippets as out-of-bounds write, out-of-bounds read, use after free or integer wraparound and cite the matching CWE for each.
  • Implement a pure-Python fixed-capacity buffer model whose write method refuses offset plus length beyond capacity, and show a flawed version silently corrupts its neighbouring field.
  • Given three tasks, choose the safe abstraction in C++ or Rust or Python (bounds-checked container, owning type, checked arithmetic) and mark exactly where an unsafe escape hatch would have to be audited.
04Secrets and configuration in code5 lessons, 2 to 4 hours

Lessons

  • Remove hard-coded credentials from source
  • Load configuration into a typed object that fails closed
  • Keep secrets out of repr, str and exception text
  • Test with canary secrets and assert they never escape
  • Layer configuration sources and show the effective value safely

After this module you can

  • Replace a credential literal in a Python module with a value read from the environment at start-up and show by test that the module refuses to start without it.
  • Build a frozen configuration object from environment strings with type conversion, range checks and safe defaults, and make start-up fail when a required or secret value is invalid.
  • Merge defaults, a settings file and environment overrides with a documented precedence, and produce a redacted dump of the effective configuration that hides secrets.
05Cryptography use and authentication primitives6 lessons, 3 to 4 hours

Lessons

  • Pick the primitive by the question it answers
  • Draw security tokens from the secrets module
  • Verify HMAC tags over unambiguous bytes with compare_digest
  • Encrypt a stored field with authenticated encryption from a library
  • Handle keys: separation, generation and rotation
  • Spot home-made cryptography in code review

After this module you can

  • Map eight requirements to hash, MAC, key-derivation function, authenticated encryption or digital signature and justify each choice in one sentence.
  • Replace a random-module token generator with secrets.token_urlsafe(32) behind an injectable function and prove by test which source is called and that tokens differ and have the required length.
  • Review a 60-line module and write findings for at least five cryptographic smells, each with location, CWE (327, 330, 311 or 312 as appropriate), impact and the library call that replaces it.
06Authorization decisions and concurrency pitfalls5 lessons, 2 to 4 hours

Lessons

  • Write one default-deny authorization function with a table test
  • Enforce the check at the action, not only at the entry point
  • Remove a check-then-act race with a lock
  • Make the database do the check-and-update atomically
  • Close a time-of-check to time-of-use window on files

After this module you can

  • Implement can(user, action, resource) as a pure function with an explicit rule table that returns False for unknown roles, actions and malformed inputs, and test it with a rule table.
  • Move an authorization call from a route-style wrapper into the function that performs the action and show a test that calling the inner function directly is also refused.
  • Replace an exists-then-open sequence with exclusive creation (open mode 'x') and an EAFP try/except, and prove by test that a pre-existing file is never overwritten.
07Secure error handling and data privacy in code6 lessons, 3 to 4 hours

Lessons

  • Catch narrowly and never let an exception grant access
  • Give callers a generic error and keep the detail internal
  • Release resources on every path with context managers
  • Collect and return only the fields the task needs
  • Redact personal data in reprs, exports and debug output
  • Create and clean up temporary files safely

After this module you can

  • Rewrite an exception handler that swallows every error and continues as success into one that catches expected exceptions only and refuses the operation on any other failure.
  • Convert a function that returns exception text and stack details to users into one that returns a generic message with a reference id while the detail goes to an internal sink passed as a parameter.
  • Replace a predictable temporary file name with tempfile.NamedTemporaryFile or mkstemp, restrict access, remove the file after use and show by test that the file is gone on error.
08Unsafe APIs, dependencies and static analysis6 lessons, 3 to 4 hours

Lessons

  • Wrap a dependency in a narrow adapter
  • Replace eval, assert-as-check and other unsafe-by-design calls
  • Run Bandit on a fixture tree and read its report
  • Triage a finding: true positive, false positive or accepted risk
  • Fix and re-scan: compare reports and use a baseline
  • Find the flaw Bandit cannot see

After this module you can

  • Put a third-party call behind a thin adapter that exposes two functions, validates what comes back and can be replaced by a fake in tests, and list what the dependency is allowed to do.
  • Replace eval on user text with ast.literal_eval or a parser, replace an assert used for validation with an explicit raise, and show the assert vanishes under python -O.
  • Show that a logic flaw (an authorization comparison using the wrong field) passes Bandit cleanly and write a unit test that fails on it, then fix it.
09Vulnerability patterns and secure code review6 lessons, 3 to 4 hours

Lessons

  • Read a CWE entry and cite it in a finding
  • Recognise the injection and encoding family in code
  • Recognise the secrets, crypto and data-exposure family
  • Recognise resource, state and memory-safety patterns
  • Turn the catalogue into a ten-item secure code review checklist
  • Review a diff with the checklist and score your findings

After this module you can

  • Read three CWE entries and write for each the weakness name, one-sentence description, an example from code in this course and the difference between a weakness and a vulnerability.
  • Given eight code snippets, label each as SQL injection, OS command injection, path traversal, eval injection, output-encoding failure or safe, with the CWE id and the course that teaches the fix.
  • Review an 80-line diff containing seven planted flaws and two decoys, write findings with location, CWE, impact and fix, and report precision and recall against the key.
10Defensive coding project4 lessons, 2 to 3 hours

Lessons

  • Specify the share-link feature and review its design with the checklist
  • Implement the share-link feature with the course's controls
  • Write defensive tests that fail on the vulnerable build
  • Verify, re-review and hand over with residual risks

After this module you can

  • Write a one-page specification for an expiring visit-summary share link and a design-review table that applies the course checklist to the specification before any code exists.
  • Implement create_link and open_link for visit summaries using a parsed visit id, a central authorization decision, an HMAC-signed expiring token with secrets-based id, an allow-listed output and generic errors.
  • Run Bandit on the project, repeat the checklist review on the implementation, compare with the design review and submit a handover note listing evidence and three honest residual risks.

What you'll build

4 guided projects along the way, then a final project.

  • Boundary and input core of Clinicdesk

    after module 3
  • Secrets, configuration and cryptography layer

    after module 5
  • Authorization, state and privacy layer

    after module 7
  • Static analysis and review pack

    after module 9

Final project

Threat-reviewed application feature with defensive tests.

What you submit

Source repository with a planted-flaw build, a fixed build and setup instructions that run locally Specification and design-review table using the course checklist, with gaps listed.

How it's reviewed

Trainer-reviewed demonstration, scored on: Coverage of checklist rows by design review and tests (25%) Evidence quality: red then green results and mutant detection (25%) Correctness of validation, cryptography use, authorization and race controls (25%).

Where you'll use it

  • Review a pull request for unsafe input handling and leaked secrets.
  • Add an authorization check and a defensive test to a feature that shares records by link.

Roles that use these skills

  • Software Developer
  • Application Security Engineer
  • Backend Developer

Earn the certificate by building, not watching

  1. Complete the lessons and pass each module checkpoint.
  2. Build your final project and demonstrate it.
  3. OUTLEARN reviews your project and issues your certificate. It is not issued automatically.

Frequently asked questions

What do I need before starting?

Prerequisite courses Programming Problem Solving and Networking Fundamentals. Because the lab language is Python, you must also be able to read and write short Python functions, use dictionaries and exceptions, run python and python -m unittest from a terminal and create a virtual environment.

When do I get a certificate?

We do not issue certificates until you successfully build and demonstrate your live project. Staff issue certificates after review; nothing is issued automatically.

Be first in when Secure Coding Fundamentals opens

Email us and we will tell you as soon as enrolment opens.

Notify me when it opens
FreeOpens soon
Notify me