Home › Web › Web Security
Web

Web Security

Web security is about keeping your site and its users safe from attackers. A few ideas prevent most common problems.

Never trust input

Anything that comes from a user, a form, a URL, a header, could be hostile. Validate it, and escape it before you put it in a page or a database query.

Common attacks

XSS injects scripts into your pages; escape output to stop it. SQL injection smuggles commands into queries; use parameterized queries. CSRF tricks a logged-in user into acting; use SameSite cookies and tokens.

-- never do this:
"SELECT * FROM users WHERE name = '" + input + "'"
-- do this:
"SELECT * FROM users WHERE name = ?", [input]

Use HTTPS

Serve everything over TLS, set the security headers, and keep your software updated. Most breaches come from skipping the basics.

Keep reading: Python  ·  TLS / HTTPS  ·  WebSockets