Skip to the content ForoHackers
Log inJoin

Secure coding: start here

Secure coding
#813 · Ophuscado · · Report

Secure coding is writing programs so that mistakes are less likely to become vulnerabilities. It is not a separate phase but a set of habits in design, naming, error handling and review. Most security bugs repeat a short list of patterns, so learning those patterns and the safe alternative to each pays off in every language.

Key concepts

  • Validate at the boundary: check type, length, range and format of every outside input, and reject rather than repair.
  • Safe by construction: parameterised queries, memory-safe languages and escaping libraries make the safe way the easy way.
  • Fail safely: on error, deny access, release resources and avoid leaking internal details in messages.
  • Secrets: never hard-code them, never log them, load them from the environment or a vault.
  • Review and tooling: code review with a security lens, plus linters, analysers and tests for abuse cases.

Vocabulary

  • Injection: untrusted data interpreted as code or commands.
  • Race condition: a result that depends on the timing of concurrent actions, sometimes a security flaw.
  • Allow-list: accepting only known-good values, rather than blocking known-bad ones.
  • Technical debt: shortcuts whose cost returns later, often as incidents.

What to study, in order

  1. The common weakness lists, with a short example and the safe version of each.
  2. Rewrite a small program that builds queries or commands by string joining, so that it uses parameters.
  3. Add input validation and clear error handling to a project of your own, with tests for hostile input.
  4. Learn the safe parts and the dangerous parts of your language's standard library.
  5. Turn on compiler warnings, a linter and a security-focused analyser in your build, and fix what they report.

Related tags

#appsec #code-review #static-analysis #testing #rust

Log in or join to reply.