CURRICULUM PREVIEWRevision 1 · Open for reviewReview the full course
CONNECTING THE PIECES8 min read

Secure coding

Treat validation, encoding, and authorization as different controls.

Before you beginthreat-modeling

The idea

Validate shape and size at input boundaries. Bind SQL parameters rather than concatenating input. Encode untrusted text for its output context. Authorization still has to decide whether the caller may act on a valid identifier; well-formed input is not permission.

Follow the flow

Make it concrete

This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.

Focused example
Go
err := pool.QueryRow(ctx,
    "SELECT id FROM bookings WHERE tenant_id=$1 AND id=$2",
    tenantID, bookingID,
).Scan(&id)
C#
var result = await db.Bookings
    .Where(b => b.TenantId == tenantId && b.Id == bookingId)
    .SingleOrDefaultAsync(ct);

Decisions that matter

  • Choose a control against a concrete risk and document its owner.
  • Exercise negative cases in authorized test fixtures.
  • Retain evidence at a specific revision and revisit it when the system changes.

Your turn

Why should a lesson renderer escape code text even though it is presented inside a code element?

Reveal a worked answer

HTML is parsed inside code elements. A literal closing tag or script text could become markup without escaping. Escape source text before adding trusted highlighting spans, and test malicious snippets through the renderer.

Keep exploring

One more piece connected.

Mark this lesson complete when you can explain the idea.