Skip to the content ForoHackers
Log inJoin

Secure coding: start here

Secure coding
#3319 · · Quote · 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

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply