Software Guides

How to Secure a Web Application: Essential Security Practices for Developers

A practical developer guide to securing web apps: the OWASP Top 10:2025, authentication, authorization, input validation, rate limiting, encryption, logging and security testing.

Brahmabyte Lab Team 10 min read Oct 19, 2026
Summarize this blog with:

Key highlights

  • Broken access control leads the OWASP Top 10:2025, so every request must be authorized on the server with a deny by default policy.
  • Follow current NIST guidance on passwords, offer multi-factor authentication and hash passwords with a slow algorithm such as Argon2id.
  • Validate input on the server with allowlists and use parameterized queries and framework escaping to block injection attacks.
  • Rate limits, HTTPS everywhere, careful configuration and up to date dependencies close many of the gaps attackers rely on.
  • Security logging, safe error handling and automated plus manual testing turn security from a one time audit into a routine.

Most web application breaches do not start with a brilliant zero day exploit. They start with ordinary gaps: an API that returns another customer's invoice when someone changes a number in the URL, an admin panel with a default password, an outdated library or a login form that allows unlimited guesses. Attackers use automated tools to find these gaps on any site they can reach, large or small.

The good news is that web application security best practices are mostly about doing well understood things consistently. You do not need a large security team to get the fundamentals right.

This guide is for developers and the founders who lead them. It covers the current OWASP Top 10, secure authentication, authorization, input validation, rate limiting, encryption, logging and security testing, with short code examples and checklists you can apply this week.

The short answer

Secure a web application by authorizing every request on the server, using proven authentication with multi-factor options and strong password hashing, validating input and using parameterized queries, encrypting data in transit and at rest, rate limiting sensitive endpoints, logging security events and testing continuously. Use the OWASP Top 10 as your baseline.

  • Deny by default and check permissions on every request
  • Use proven libraries for authentication and cryptography
  • Automate security checks in your CI pipeline

Start with the OWASP Top 10:2025

The OWASP Top 10 is a standard awareness document that represents a broad consensus about the most critical security risks to web applications. The current edition is the OWASP Top 10:2025. It is not a complete checklist, but it is the best place to start a security review.

RankCategoryWhat it looks like in practice
A01Broken Access ControlA user views or edits data that belongs to someone else
A02Security MisconfigurationDebug mode, default accounts or open storage left in production
A03Software Supply Chain FailuresCompromised or vulnerable dependencies and build tools
A04Cryptographic FailuresSensitive data sent or stored without proper encryption
A05InjectionSQL injection or cross site scripting from untrusted input
A06Insecure DesignSecurity controls missing from the design itself
A07Authentication FailuresCredential stuffing, weak passwords or poor session handling
A08Software or Data Integrity FailuresUnverified updates or untrusted data treated as code
A09Security Logging and Alerting FailuresAttacks happen and nobody notices
A10Mishandling of Exceptional ConditionsErrors that fail open or leak sensitive details

According to the OWASP introduction to the 2025 edition, there are two new categories and one consolidation. Server-side request forgery has been rolled into Broken Access Control, Software Supply Chain Failures expands the earlier category on vulnerable and outdated components, and Mishandling of Exceptional Conditions is new. Security Misconfiguration moved up from fifth place in 2021 to second.

To put the list to work, map each category to a named owner and a concrete control in your codebase. Broken access control maps to a shared authorization module and tests, supply chain failures to dependency scanning, and logging failures to a defined list of security events. Review the mapping whenever you add a major feature or integration.

Authorization: check every request on the server

Authentication answers who the user is. Authorization answers what they are allowed to do. OWASP's A01 page reports that 100% of the applications tested were found to have some form of broken access control, which is why it holds first place.

The OWASP Authorization Cheat Sheet sets out the core rules: deny access by default, apply least privilege, validate permissions on every request and never rely on client side checks. Hiding a button in the interface is good user experience, not security, because an attacker can call the API directly.

// Check ownership on the server, on every request
app.get('/api/invoices/:id', requireAuth, async (req, res) => {
  const invoice = await db.invoice.findById(req.params.id)
  if (!invoice || invoice.accountId !== req.user.accountId) {
    return res.status(404).json({ error: 'Not found' })
  }
  res.json(invoice)
})

Returning a not found response for records the user cannot access avoids confirming that they exist. In multi tenant SaaS products, scope every database query by tenant or account ID, and keep permission rules in one shared module so the web app, mobile API and background jobs enforce the same policy.

Secure authentication and session handling

Use a well maintained authentication library or identity provider rather than building login, password reset and session logic from scratch. Offer multi-factor authentication to all users and require it for administrators and anyone with access to customer data.

Password rules have changed. NIST's SP 800-63B-4 requires a minimum of 15 characters when a password is the only authentication factor, and at least 8 when it is used as part of multi-factor authentication. It says verifiers should not impose composition rules such as mixing character types or force periodic password changes, but must compare new passwords against a blocklist of commonly used, expected or compromised passwords, and must force a change when there is evidence of compromise.

Account recovery is a frequent weak point. Password reset links should use single use, short lived random tokens, the reset form should not reveal whether an email address is registered, and users should be notified whenever their password or recovery details change.

Store passwords with a slow, salted hashing algorithm. The OWASP Password Storage Cheat Sheet recommends Argon2id with a minimum of 19 MiB of memory, an iteration count of 2 and a parallelism of 1. It lists scrypt as the fallback, bcrypt only for legacy systems with a work factor of 10 or more, and PBKDF2 with at least 600,000 iterations where FIPS compliance is required.

  • Set session cookies with the HttpOnly, Secure and SameSite attributes
  • Issue a new session ID after login and after privilege changes
  • Expire idle sessions and invalidate them on the server at logout
  • Use the same generic message for wrong usernames and wrong passwords
  • Ask for re-authentication before sensitive actions such as changing email, adding API keys or exporting data

Input validation and injection prevention

Treat every input as untrusted: request bodies, query strings, headers, cookies, uploaded files and webhook payloads. Validate on the server using allowlists that check type, length, format and range. The OWASP Input Validation Cheat Sheet explains how to design these rules. Validation in the browser improves user experience but protects nothing.

Injection happens when untrusted data is mixed into a command or query. The first primary defense in the OWASP SQL Injection Prevention Cheat Sheet is parameterized queries, so the database driver sends values separately from the SQL code instead of pasting them into it.

// Unsafe: user input becomes part of the SQL text
db.query("SELECT * FROM users WHERE email = '" + email + "'")

// Safe: the value is sent separately as a parameter
db.query('SELECT * FROM users WHERE email = $1', [email])

For cross site scripting, rely on your framework's automatic output escaping and avoid inserting raw HTML from users. Add a Content Security Policy to limit which scripts can run. For file uploads, check type and size, rename files and store them outside the public web root.

Rate limiting and abuse protection

Without limits, attackers can try thousands of stolen passwords, scrape your data or trigger expensive operations such as SMS one time codes. The OWASP API Security Top 10 lists Unrestricted Resource Consumption as a top API risk in its 2023 edition.

  • Limit login and password reset attempts per account and per IP address, with increasing delays
  • Set per key or per user request quotas for your API
  • Cap page sizes, upload sizes and request body sizes
  • Apply stricter limits to costly actions such as exports, search and OTP sending
  • Return a 429 status with a Retry-After header so legitimate clients can back off
Protect the business flow, not just the endpoint

Think about what an attacker gains from automation. A coupon endpoint, a free trial sign up or a booking form may need limits per account, per device or per payment method, not just per IP address.

Encryption in transit and at rest

Serve everything over HTTPS, redirect plain HTTP and add the Strict-Transport-Security header, which tells browsers to access your site only over HTTPS in future. Encrypt connections between your services and databases too, not just the public edge.

For data at rest, enable encryption on databases, storage buckets and backups, and consider field level encryption for highly sensitive values such as national ID numbers or third party access tokens. Keep encryption keys in a key management service, not in source code or environment files committed to Git.

Remember that passwords are hashed, not encrypted. Encryption is reversible by design, while password hashes should never need to be reversed. In both cases, use vetted libraries and never invent your own cryptography.

Configuration, security headers and dependencies

Security misconfiguration now ranks second in the OWASP list. Common examples include debug mode left on in production, detailed stack traces shown to users, default admin accounts, overly permissive CORS rules and cloud storage that anyone can list. Use infrastructure as code and environment checklists so production settings are reviewed, not improvised.

  • Content-Security-Policy to restrict where scripts and other resources load from
  • Strict-Transport-Security to enforce HTTPS
  • X-Content-Type-Options: nosniff to stop browsers guessing content types
  • A frame-ancestors policy to prevent clickjacking
  • Referrer-Policy to control what URL data leaves your site

Supply chain risk deserves the same attention. Commit lockfiles, update dependencies regularly with automated pull requests, remove unused packages and limit what your CI pipeline is allowed to access. Our DevOps for beginners guide explains how to keep secrets out of code and pipelines.

Logging, alerting and safe error handling

You cannot respond to attacks you never see. Log security relevant events such as successful and failed logins, password resets, permission denials, admin actions and validation failures, with timestamps, user IDs and request IDs. The OWASP Logging Cheat Sheet warns against recording sensitive values such as passwords and session identifiers directly.

Error handling matters for the new A10 category. Fail closed: if a permission check or payment verification throws an error, deny the action rather than allowing it. Show users a generic message, keep technical details in your logs, and make sure an exception halfway through a workflow does not leave data in an inconsistent state.

Turn logs into alerts for patterns that signal trouble, such as a spike in failed logins, many permission denials from one account or unusually large data exports.

Protect the logs themselves. Send them to a central system that the application cannot modify, restrict who can read them, and set a retention period that balances investigation needs with privacy obligations.

Security testing in your development workflow

Security works best as a routine built into delivery rather than a single audit before launch. A practical sequence looks like this.

  1. 1

    Threat model new features

    Before building, ask what could be abused, who could abuse it and what controls are needed. This addresses insecure design at the cheapest stage.

  2. 2

    Scan code and secrets in CI

    Run static analysis and secret scanning on every pull request so obvious mistakes never merge.

  3. 3

    Check dependencies continuously

    Use automated dependency scanning and act on high severity findings promptly.

  4. 4

    Write authorization tests

    Add tests that prove user A cannot read or change user B's data, and run them on every build.

  5. 5

    Scan the running application

    Run a dynamic scanner such as the open source ZAP against a staging environment.

  6. 6

    Bring in manual testing

    Schedule penetration tests before major launches and use the OWASP ASVS as a checklist of security requirements to verify.

No single tool finds everything

Automated scanners are good at known patterns such as missing headers and outdated libraries. They are weak at business logic flaws, such as one customer reading another customer's records through a valid API call. That is why authorization tests and human review remain essential.

If your product exposes APIs, our comparison of REST vs GraphQL vs gRPC covers the authorization quirks of each API style.

Conclusion: make security a habit, not an event

Securing a web application is a series of small, consistent decisions: authorize every request, handle passwords and sessions carefully, validate input, limit abuse, encrypt data, keep configuration and dependencies tidy, log what matters and test continuously. The OWASP Top 10:2025 gives you a clear starting point, and each control you add makes your product harder to attack and easier to trust. If you want experienced engineers to review your application or build security into your next release, contact Brahmabyte Lab for a free first consultation.

Frequently asked questions

The current edition is the OWASP Top 10:2025. It is led by Broken Access Control, followed by Security Misconfiguration and Software Supply Chain Failures, and it adds a new category called Mishandling of Exceptional Conditions. Always check the official OWASP site for the latest edition.

Authentication confirms who a user is, for example through a password and a one time code. Authorization decides what that user is allowed to see or do. Many serious breaches happen when authentication works correctly but authorization checks are missing.

The OWASP Password Storage Cheat Sheet recommends Argon2id first, scrypt if Argon2id is unavailable, and bcrypt only for legacy systems. Never store passwords in plain text or with fast general purpose hashes. Use a well maintained library rather than writing your own implementation.

No. HTTPS protects data while it travels between the browser and your server, but it does nothing against broken access control, injection or weak passwords. It is a required baseline, not a complete security strategy.

Automated checks such as dependency scanning, static analysis and authorization tests should run on every change in your CI pipeline. Dynamic scans of staging can run regularly, and manual penetration tests are worth scheduling before major launches and after significant changes.

Yes. Automated attacks such as credential stuffing and vulnerability scanning target any reachable website, regardless of company size. Many of the most effective protections, such as server side authorization, strong password storage and dependency updates, cost little beyond developer discipline.

Sources and references

  1. OWASP Top 10:2025, OWASP Foundation
  2. NIST SP 800-63B-4: Authentication and Authenticator Management, National Institute of Standards and Technology (NIST)
  3. Password Storage Cheat Sheet, OWASP Cheat Sheet Series
  4. Authorization Cheat Sheet, OWASP Cheat Sheet Series

Cover photo by Dan Nelson

Stay in the loop

Get our latest guides on software, SaaS and growth delivered to your inbox.

By subscribing, you agree to get updates from Brahmabyte Lab. You can unsubscribe any time.
Back to blog
Let’s work together

Ready to build your next big idea?

Partner with Brahmabyte Lab to turn your idea into a fast, scalable SaaS product. Let us talk about your project today.