Security

10 posts on Security from funGyaan: curious questions answered simply, readable as a series from part 1 or newest first.

  1. How should you store passwords?

    With a slow, memory-hard password hash (argon2id, or scrypt or bcrypt), a unique salt per password, and settings that make each guess cost tens of milliseconds. A fast hash like SHA-256 lets a GPU try billions of guesses a second. Plus the parts around the hash that matter as much: rate limits…

    · 6 min read · Security

  2. CSRF, CORS and SameSite cookies: what each actually protects

    CORS doesn't protect your server; it decides which other sites may read your responses in a browser. CSRF is another site making the browser send a request with your cookies, and SameSite cookies stop most of it, but not all. Fetch Metadata headers and a CSRF token close the rest. What each layer…

    · 5 min read · Security

  3. API keys, OAuth client credentials or mTLS: how should services authenticate?

    API keys are simple and fine for low-risk public APIs if they're hashed, scoped and rotatable. OAuth client credentials give short-lived, scoped tokens and central control. Mutual TLS proves identity at the connection level and suits internal service meshes. Signed requests (HMAC) protect…

    · 6 min read · Security

  4. OAuth 2.0 and OpenID Connect: which flow for which client?

    Authorization code with PKCE for anything with a user (web, SPA, mobile, desktop), client credentials for machine-to-machine, the device flow for TVs and CLIs. The implicit and password grants are retired. OAuth is about access to APIs; OpenID Connect adds who the user is. Diagrams of each flow.

    · 6 min read · Security

  5. Which kind of 2FA should you offer?

    SMS codes are better than nothing and the weakest option. Authenticator-app codes (TOTP) stop password reuse but not phishing. Push approvals invite fatigue attacks. Security keys and passkeys are the only phishing-resistant option. What each defends against, what to offer, and why recovery codes…

    · 5 min read · Security

  6. RBAC, ABAC or ReBAC: how should you model permissions?

    Roles answer "what can an editor do?", attributes answer "under which conditions?", relationships answer "who can see this particular document?". Most SaaS products need roles per tenant plus a few attribute rules; sharing features need relationships. Where to enforce them, and why the database…

    · 5 min read · Security

  7. Sessions or JWTs: which should you use to keep users signed in?

    Two good ideas for different jobs. For a web app with its own backend, server-side sessions are simpler and safer: a random cookie, instant revocation, nothing sensitive in the browser. JWTs earn their place between services and across organisations, where checking a signature beats a database…

    · 5 min read · Security

  8. How should users sign up?

    Email and password is universal but leaves you guarding passwords. Magic links remove passwords but depend on email speed. Social login is one click but ties users to another company. Passkeys are the most secure and still unfamiliar to many. B2B customers will ask for SSO. How to choose, and how…

    · 6 min read · Security

  9. Encoding, encryption, hashing, signing: what's the difference?

    Encoding changes format and protects nothing. Encryption hides data from anyone without the key and can be reversed. Hashing can't be reversed and proves data hasn't changed. Signatures and MACs prove who produced the data. Which one to use for passwords, secrets, webhooks, tokens and files, with…

    · 5 min read · Security

  10. Access tokens and refresh tokens: why two, where do they live, and what happens when one leaks?

    Why two tokens: a short-lived access token shown to every API, and a longer-lived refresh token shown only to the auth server and rotated, so reusing a stolen one raises an alarm. Diagrams of the flows, where to store each token on web, mobile and server, and what an attacker gets from each kind…

    · 7 min read · Security