Attacks and defenses

08·Concept·10 min

Most attacks on a web app are not clever. They are automated, cheap, and aimed at every site on the internet at once. Each has a standard defense.

Injection

An attacker types something into a form that the app pastes into a database query or a page. If the input becomes part of the command, it can read or delete data (SQL injection) or run script in other visitors' browsers (XSS). Defense: never build commands from text. Parameterize queries, and escape everything rendered into a page.

Brute force and credential stuffing

Guessing passwords, or replaying email and password pairs leaked from other sites. Defense: rate limits on login, lockouts after repeated failures, a password policy that rules out the most common guesses, and MFA, a second factor from an authenticator app that a leaked password cannot satisfy.

Bots

Scripts that sign up thousands of fake accounts, scrape prices, or submit spam. Defense: a bot check on the forms that matter (sign in, sign up, password reset), plus rate limits per address.

Fake accounts usually need fake email addresses too: domains that take no mail, or disposable inboxes that vanish after an hour. Defense: an email check at sign-up that asks whether the domain can receive mail and refuses known throwaway services, before any account exists.

Denial of service

Flooding a site with requests until it cannot answer real ones. Defense: a WAF (web application firewall) in front of the app, which recognizes attack patterns and abusive addresses and drops them before they reach your server.

Secrets

The quiet failure: an API key committed to a repository, a database password in a page. Defense: keep secrets on the server, store only hashes of keys, and revoke first, investigate second.

Where DontCode fits

The platform WAF blocks attacks automatically, and the Protection page shows how many visits it blocked in the last 30 days, with the list under Details on plans that include it. Sign-up checks every email address on its own, and Protection's Sign-up emails row counts the fake and throwaway ones it turned away. On an Insight Project's Users, Sign-in settings, the Account security section has one switch that turns on the bot check for sign in, sign up, and password reset, next to the password rules and Two-Step Verification; the same two switches sit on the Protection page. Queries through the public API are parameterized on the server, OAuth secrets are write-only, and API keys are stored as hashes.

Check your understanding

  1. 1.What is the standard defense against SQL injection?

  2. 2.An attacker has a list of email and password pairs leaked from another site. Which defense stops a correct pair from working?

  3. 3.Where does a WAF sit?

  4. 4.You discover an API key in a public repository. First step?

  5. 5.Someone opens hundreds of free trials with addresses from a disposable inbox service. Which defense stops them at sign-up?