Tag: OWASP

  • HTTP Security Headers: What to Set, How to Configure Them and How to Test

    HTTP Security Headers: What to Set, How to Configure Them and How to Test

    HTTP security headers checklist graphic: shield with HSTS, CSP and nosniff labels

    Introduction

    HTTP security headers are response headers that tell the browser how to treat your pages. They are cheap to add and they limit the damage of bugs such as cross-site scripting (XSS), clickjacking and downgrade attacks. This guide lists the HTTP security headers worth setting as of November 23, 2026, gives copy-ready nginx and Apache examples, and shows how to roll out the risky ones (HSTS and CSP) safely. It follows the OWASP HTTP Headers Cheat Sheet and MDN documentation. No header replaces patching, so keep your software updated too.

    Key Facts: HTTP Security Headers at a Glance

    • Set on every HTML response: Strict-Transport-Security, Content-Security-Policy, X-Content-Type-Options, Referrer-Policy, Permissions-Policy.
    • Framing: use CSP frame-ancestors. OWASP says it obsoletes X-Frame-Options; X-Frame-Options: DENY is the fallback.
    • Do not rely on: X-XSS-Protection (OWASP: set 0 or omit), Expect-CT and Public-Key-Pins (HPKP; OWASP: do not use).
    • Riskiest to deploy: HSTS (mistakes lock users out) and CSP (can break scripts). Roll both out in stages.
    • Nginx gotcha: add_header is inherited only if the current level defines no add_header of its own.
    • Test with: curl -I, browser DevTools and the Mozilla Observatory.

    Which HTTP Security Headers Should You Set?

    Set the headers below on pages that browsers render. The values come from the OWASP HTTP Headers Cheat Sheet.

    HeaderRecommended value (OWASP)What it does
    Strict-Transport-Securitymax-age=63072000; includeSubDomains; preloadMakes browsers use HTTPS only
    Content-Security-PolicySee the CSP section belowLimits where scripts and other content load from
    X-Content-Type-OptionsnosniffStops MIME type sniffing
    Referrer-Policystrict-origin-when-cross-originLimits referrer data sent to other sites
    Permissions-Policygeolocation=(), camera=(), microphone=()Disables browser features you do not use
    Cross-Origin-Opener-Policysame-originIsolates your page from cross-origin windows
    Cross-Origin-Resource-Policysame-siteLimits which origins can load your resources
    X-Frame-OptionsDENYBlocks framing (legacy; prefer CSP frame-ancestors)

    OWASP notes that CSP, COOP and similar headers matter for pages browsers render, and may be meaningless on a JSON API. Adjust the Permissions-Policy list to the features your site really needs.

    What Is HSTS and How Do You Roll It Out Safely?

    HSTS (HTTP Strict Transport Security) tells a browser to reach your site only over HTTPS. Browsers honor it only when it arrives over HTTPS (RFC 6797 forbids sending it over plain HTTP).

    OWASP warns that a misconfigured header or an expired certificate can lock legitimate users out for the whole max-age. MDN therefore suggests a staged rollout with includeSubDomains:

    1. max-age=300; includeSubDomains (5 minutes).
    2. max-age=604800; includeSubDomains (1 week).
    3. max-age=2592000; includeSubDomains (1 month).
    4. Only then raise max-age. For the preload list, max-age must be at least 31536000 (1 year) and both includeSubDomains and preload must be present.

    Wait the full max-age of each stage before the next one.

    HTTP security headers HSTS staged rollout: 5 minutes, 1 week, 1 month, then at least 1 year for preload
    Staged HSTS rollout recommended by MDN, with the 1-year minimum needed for preload.

    Preloading is hard to undo, and it covers all subdomains, so submit to hstspreload.org only when every subdomain serves HTTPS.

    How Do You Build a Content Security Policy?

    A Content Security Policy (CSP) lists which sources may load scripts and other content, so injected scripts are blocked. OWASP’s nonce-based strict policy is a good target:

    Content-Security-Policy: script-src 'nonce-{RANDOM}' 'strict-dynamic'; object-src 'none'; base-uri 'none';

    The nonce must be a fresh random value for every response and must be added to your own <script> tags by a real templating engine. OWASP warns against a middleware that adds the nonce to all script tags, because injected scripts would get it too. Static HTML cannot use nonces; OWASP offers a hash-based variant for that case.

    Start with Content-Security-Policy-Report-Only. MDN explains that this mode does not enforce the policy but reports violations, so you can fix inline code before you enforce. For framing, add frame-ancestors 'none' (or 'self') in the enforced CSP.

    How Do You Add HTTP Security Headers in Nginx and Apache?

    Use the web server’s header module and the always option so error pages get the headers too. Both examples use values from OWASP; replace the CSP with your tested policy.

    Nginx

    server {
        add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "strict-origin-when-cross-origin" always;
        add_header Permissions-Policy "geolocation=(), camera=(), microphone=()" always;
        add_header Cross-Origin-Opener-Policy "same-origin" always;
    }

    The nginx documentation says add_header directives are inherited from the previous level if and only if the current level defines none. A single add_header inside a location block therefore drops all server-level headers for that location. Since nginx 1.29.3 the add_header_inherit directive (on, off or merge) can change this. Use merge only after checking your nginx version and testing.

    Apache HTTP Server

    <IfModule mod_headers.c>
        Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
        Header always set X-Content-Type-Options "nosniff"
        Header always set Referrer-Policy "strict-origin-when-cross-origin"
        Header always set Permissions-Policy "geolocation=(), camera=(), microphone=()"
    </IfModule>

    The Apache documentation says the always table adds headers even on errors and keeps them across internal redirects. If your application framework already sets some of these headers, avoid duplicates and set each header in one place.

    How Can You Check Which HTTP Security Headers Your Site Sends?

    Request only the headers with curl and read the response:

    curl -sI https://example.com/ | grep -iE "strict-transport|content-security|x-content-type|referrer-policy|permissions-policy|cross-origin|x-frame"

    Replace example.com with your own domain. Check the home page, a login page and an error page, because a location block or an application can change the headers. The Mozilla Observatory, which OWASP lists for this purpose, scans a site and reports missing headers. Online tools usually test only the home page.

    What Else Should You Harden?

    • Remove version leaks. OWASP advises removing X-Powered-By and hiding or genericizing Server, though attackers have other ways to fingerprint a stack.
    • Set Cache-Control for sensitive pages. OWASP recommends no-store for sensitive responses. no-cache does not stop caching; it only requires revalidation. Proxies and filters can change these headers, as the ExpiresFilter bug in our Apache Tomcat security update article shows.
    • Remove obsolete headers. Drop Public-Key-Pins. OWASP says it was removed from Chromium in 2018 and recommends relying on Certificate Transparency and CAA DNS records.
    • Patch the server. Headers reduce impact but do not fix bugs. See our nginx and Apache HTTP Server update guides.
    • Add a WAF in front. It is a second layer, not a substitute.

    FAQ

    Do HTTP security headers stop XSS completely?

    No. A strict CSP is the strongest header-based defense against XSS, but you still need output encoding and input validation. Treat headers as defense in depth.

    Is X-XSS-Protection still needed?

    No. OWASP recommends a CSP that disables inline JavaScript and says not to set X-XSS-Protection or to set it explicitly to 0. MDN warns it can create XSS holes in otherwise safe sites.

    Should I still use X-Frame-Options?

    Prefer CSP frame-ancestors, which OWASP says obsoletes it in supporting browsers. Keeping X-Frame-Options: DENY as well is harmless for pages that must never be framed.

    Can HSTS break my site?

    Yes, if HTTPS breaks or a subdomain lacks HTTPS while includeSubDomains is set. Start with a short max-age and increase it in stages, as described above.

    Do I need these headers on API responses?

    Mostly not all of them. OWASP notes CSP, COOP and related headers may be meaningless on JSON responses that browsers do not render. X-Content-Type-Options: nosniff, correct Content-Type and HSTS still make sense.

    How often should I review my security headers?

    Review them after every server, proxy or framework change. Browser support and recommendations change, so recheck the OWASP cheat sheet. Values here were verified on November 23, 2026.

    Conclusion

    HTTP security headers take an afternoon to add and cut the impact of common web attacks. Start with HSTS (staged), nosniff, a Referrer-Policy and Permissions-Policy, then move CSP from report-only to enforced. Test every change with curl and the Mozilla Observatory.

    References

    All links below were checked on November 23, 2026.

    Related Articles

    Last Verified: November 23, 2026. Prepared by SafeWebAcademy from OWASP, MDN, IETF, nginx and Apache documentation linked above. Header recommendations can change; recheck the sources before deploying.

  • OWASP Top 10 Explained: A Practical Guide to Website Security

    OWASP Top 10 Explained: A Practical Guide to Website Security

    owasp

    1. What Is the OWASP Top 10, and Why Does It Matter?

    The OWASP Top 10 is an awareness document describing ten critical categories of web application security risk. It helps developers, engineers, website maintainers and owners understand common weaknesses and prioritize safer decisions before those weaknesses become costly incidents.

    OWASP stands for the Open Worldwide Application Security Project, a nonprofit foundation that provides security resources. Its official OWASP Top 10 project page explains the risks and links to guidance for addressing them. This guide covers the OWASP Top 10:2025 edition, including categories such as Broken Access Control, Security Misconfiguration and Software Supply Chain Failures.

    These risks matter because application security affects more than code. A weakness in an online store could expose customer information, let someone take over an account or interrupt checkout. The consequences can include lost sales, recovery costs and damaged trust.

    For website teams, the list provides a shared starting point for discussing what could go wrong and where protection needs improvement. You do not need to be a security specialist to use it, but you do need to connect its lessons to your website’s features, data and users.

    2. How to Use the OWASP Top 10 Without Treating It as a Checklist

    Each OWASP Top 10 entry describes a broad risk category, not a single bug to fix and check off. In an online store with customer accounts, checkout and an administrator dashboard, broken access control could let customers view another shopper’s orders or reach administrative functions. These are different weaknesses within the same category.

    Use the list to guide awareness and priorities. It is not a complete security standard, a certification or proof that your website is secure. Your store may also have business-specific risks, such as checkout rules that allow discounts to be combined in unintended ways.

    Responsibility should be shared but explicit:

    • Developers implement safeguards in application code.
    • Maintainers manage updates, dependencies and configuration.
    • Owners fund security work and assign accountability.

    Protection works best in layers. Secure design establishes the rules, careful implementation enforces them, and dependency management reduces exposure through third-party software. Testing checks whether controls work, while monitoring helps identify suspicious activity and failures after deployment.

    Automated scanners support this work, but they cannot reliably detect every authorization or business-logic flaw. A scanner may flag an outdated library yet miss that one customer can access another’s invoice. Combine automated checks with manual reviews of important user journeys.

    3. OWASP Top 10 Risks 1–5: Access, Configuration, Dependencies, Encryption and Injection

    A01:2025, Broken Access Control

    Users can access information or actions beyond their permissions. In an online store, changing an order ID might reveal another customer’s purchase. Enforce authorization on the server for every relevant request, and deny access by default.

    A02:2025, Security Misconfiguration

    Unsafe settings leave applications exposed. For example, a production checkout page might display debugging errors containing sensitive details. Harden production configurations, disable unnecessary features and keep secrets out of public files.

    A03:2025, Software Supply Chain Failures

    Weaknesses in dependencies, build systems or software distribution can compromise your website. A compromised package could introduce malicious code during an update. Track dependencies, review updates and protect build pipelines with restricted access.

    A04:2025, Cryptographic Failures

    Missing or misused cryptographic protections expose sensitive information. For example, customer details sent without HTTPS can be intercepted. Enforce HTTPS, use established cryptographic libraries, protect encryption keys and store passwords using appropriate password-hashing algorithms, such as Argon2id.

    A05:2025, Injection

    Untrusted input becomes part of a command or executable content. For example, an unsafe search field could let input alter a database query. Use parameterized queries for database operations and context-appropriate output encoding when displaying untrusted content. Input filtering alone is not a sufficient defense.

    4. OWASP Top 10 Risks 6–10: Design, Authentication, Integrity, Monitoring and Error Handling

    A06:2025, Insecure Design

    Security safeguards are missing from the application’s design. For example, an online store’s password-reset flow allows unlimited automated requests. Define security requirements before implementation, use threat modeling to identify potential threats, and review how legitimate features could be abused.

    A07:2025, Authentication Failures

    Weak login or session controls let attackers impersonate users. For example, repeated password guesses face no meaningful resistance. Use multifactor authentication where appropriate, secure session handling, and rate limits or other defenses against automated login attacks.

    A08:2025, Software or Data Integrity Failures

    The application trusts software or data without adequate integrity checks. For example, it accepts an update without verifying authenticity. Verify trusted sources and signatures where applicable, and avoid unsafe deserialization, which can turn untrusted stored or transmitted data into dangerous application behavior.

    A09:2025, Security Logging and Alerting Failures

    Suspicious activity goes unrecorded or unnoticed. For example, repeated administrator login failures generate no alert. Record useful security events, protect logs against unauthorized access or alteration, and assign responsibility for investigating alerts.

    A10:2025, Mishandling of Exceptional Conditions

    Unexpected failures trigger unsafe behavior. For example, an authorization check encounters an error, but checkout administration remains accessible. Fail securely by denying access when checks fail, handle errors consistently, and test unusual conditions without exposing sensitive details.

    5. Turn OWASP Guidance Into a Practical Website Security Routine

    Start with a repeatable process that turns OWASP awareness into assigned work:

    1. Inventory applications and dependencies, including plugins, third-party services and software versions.
    2. Identify sensitive data and privileged functions, such as customer records, payment workflows and administrator access.
    3. Review relevant OWASP risks against those systems and workflows.
    4. Assign remediation owners and deadlines, then verify that fixes work.

    Prioritize by exposure, exploitability and business impact, not category ranking alone. A publicly reachable authorization flaw may need attention before a low-impact internal configuration issue.

    Establish the foundations: supported software, timely security updates, HTTPS, least-privilege access, protected secrets and multifactor authentication for administrative accounts.

    Build dependency scanning, code review and automated security testing into development and maintenance. Add manual authorization testing and security-focused regression tests to catch permission failures and prevent fixed weaknesses from returning. Test only systems you own or are authorized to assess.

    Small teams can start with a manageable baseline and expand it. Document incident-response contacts, configure actionable alerts and test backups regularly. Backups support recovery, but do not prevent vulnerabilities.

    For detailed requirements, use the OWASP Application Security Verification Standard. For implementation guidance, consult the OWASP Cheat Sheet Series.

    6. Keep Learning From OWASP and Make Security Continuous

    The OWASP Top 10 gives website teams a shared vocabulary for important application risks. Its value comes from applying that knowledge consistently across design, development and operations, not from reviewing the list once and considering security finished.

    Start with three practical steps:

    1. Review one critical user journey. Choose a process such as signing in, resetting a password or completing checkout. Check how it handles permissions, sensitive information and unexpected failures.
    2. Address the highest-impact weakness you discover. Consider the likely harm to customers and the business, then assign someone responsibility for fixing and verifying it.
    3. Schedule a recurring security review. Revisit protections after significant releases, dependency changes or new features. Give each review an owner so it becomes part of routine maintenance.

    Use the official OWASP Top 10 project page to explore the current edition, category explanations and linked guidance. Share relevant material with everyone responsible for building, maintaining or funding your website, so security decisions do not depend on one person’s knowledge.

    Understanding the basics helps teams ask better questions and make safer decisions. No single list, tool or review can eliminate every risk. The clear takeaway: use OWASP as a foundation for continuous security work, not as a finish line.

    Related reading

  • Complete Guide to Web Application Firewall WAF

    Complete Guide to Web Application Firewall WAF

    Diagram of a web application firewall filtering traffic between users and a web server

    A web application firewall, or WAF, is one of the most effective ways to protect websites and APIs from common attacks without slowing down development. Think of it as a smart security layer that sits in front of your app and filters bad traffic before it reaches your code. In this complete guide to WAF, you’ll learn what a WAF is, how it works, and the best practices to deploy, tune, and maintain it for strong and reliable web application security.

    What Is a Web Application Firewall (WAF)?

    A Web Application Firewall is a security control that monitors and filters HTTP and HTTPS traffic between a client and a web application. Unlike a traditional network firewall that focuses on IPs, ports, and protocols, a WAF operates at Layer 7 and understands web requests, parameters, headers, and payloads. This application awareness allows it to block threats like SQL injection, cross-site scripting, file upload abuse, and other risks highlighted in the OWASP Top 10.

    WAFs come in several forms: cloud WAF delivered at the edge, on-premises or virtual appliances you manage, and WAF as part of a CDN or WAAP (Web Application and API Protection) platform. Cloud WAFs are quick to deploy and scale easily, while on-premises WAFs give you more control and can satisfy strict data residency or regulatory needs. Many teams start with a cloud WAF to gain fast coverage, then refine policies as their traffic and compliance needs evolve.

    Beyond blocking attacks, a WAF provides visibility and control. It helps with PCI DSS 6.6 compliance requirements, supports virtual patching for zero-days, and integrates with DevSecOps workflows. With detailed logs and analytics, a WAF turns noisy web traffic into actionable security signals, making it easier for security and engineering teams to collaborate on risk reduction without disrupting release cycles.

    How a WAF Works: Core Features and Benefits

    At its core, a WAF inspects each request and response, applying rules that look for suspicious patterns, anomalous behavior, and known bad signatures. It can enforce both a negative security model (block known bad) and a positive security model (allow known good), sometimes combining them for better accuracy. Advanced engines add behavior scores, reputation feeds, and machine learning to adapt to new attack techniques while reducing false positives.

    Key capabilities include rate limiting, bot mitigation, and IP reputation filtering to cut automated abuse like credential stuffing and carding. Many WAFs validate JSON and XML payloads for API security, enforce HTTP method and content-type controls, and apply path-based policies. Features like TLS termination, header normalization, and security header enforcement (HSTS, CSP, X-Frame-Options) improve baseline hygiene. With geo-blocking, virtual patching for CVEs, and granular rules per endpoint, a WAF helps contain risk quickly.

    The benefits are practical and measurable. You get stronger protection against OWASP Top 10 risks, faster response to zero-days, and reduced load on your origin by filtering malicious traffic early. Detailed request logs help investigations and feed SIEM and SOAR tools for better incident response. With a well-tuned WAF, teams lower mean time to detect and remediate, protect uptime during L7 DDoS events, and support compliance without adding heavy friction to development.

    WAF Setup Best Practices, Tuning, and Rules

    Start with a careful rollout. Put the WAF in monitoring or detection-only mode first to learn your normal traffic and reduce false positives. Baseline your endpoints, parameters, and authentication flows, then move high-confidence rules to block mode. Segment policies by environment and application, keep custom rules in version control, and test changes in staging with canary releases before you push to production.

    Tune for precision and performance. Use allowlists for trusted services and health checks, and create path-based policies for sensitive routes like login, checkout, and admin pages. Limit HTTP methods and content types per endpoint, set strict upload size limits, and validate file extensions and MIME types. Add rate limits by IP, user, and API token to protect login and search endpoints, and enable bot challenges where appropriate. For APIs, enforce schema validation, reject unknown fields, and consider mTLS for machine-to-machine traffic.

    Maintain a continuous improvement loop. Review WAF logs daily at first to catch false positives and refine rules quickly. Track metrics like false-positive rate, rule hit counts, blocked vs allowed traffic, latency overhead, and incident response times. Keep your core rule set (such as the OWASP ModSecurity CRS) up to date, apply virtual patches for new CVEs, and audit policies regularly for drift. Document ownership, change windows, and rollback steps, and automate WAF configuration with infrastructure as code to ensure consistent, repeatable security.

    FAQ: Web Application Firewall (WAF)

    Q: Is a WAF enough to secure my app?
    A: No. A WAF is a strong layer in defense in depth, but you still need secure coding, regular patching, dependency scanning, and runtime monitoring.

    Q: What’s the difference between a WAF and an API gateway?
    A: An API gateway focuses on routing, authentication, throttling, and developer experience. A WAF focuses on security inspection and threat mitigation. Many teams use both, or a WAAP that blends features.

    Q: Will a WAF slow down my site?
    A: A well-tuned WAF adds minimal latency, often a few milliseconds. Use edge deployments, cache-friendly rules, and avoid overly complex custom logic on hot paths.

    Q: Can a WAF stop DDoS attacks?
    A: It helps with application-layer (L7) DDoS like request floods. For large volumetric (L3/L4) DDoS, pair your WAF with a network-level DDoS protection service.

    Q: Cloud WAF or on-premises WAF?
    A: Choose cloud WAF for speed, scale, and global reach. Choose on-prem for strict data control, custom routing, or specialized compliance.

    Q: How do I measure WAF ROI?
    A: Track reduced incidents, fewer fraudulent or abusive requests, lower origin load, faster zero-day response, and less downtime during attack spikes.

    Q: How do I reduce false positives?
    A: Start in monitor mode, tune high-traffic routes first, use allowlists and parameter-specific rules, and review logs daily until stable.

    Q: Do I need a WAF if I already use a CDN?
    A: Many CDNs include a WAF, but depth and features vary. Ensure you get robust rules, good analytics, and API security capabilities.

    A Web Application Firewall gives you fast, adaptable protection for websites and APIs by stopping attacks at the edge before they hit your code. When you deploy it in monitor-first mode, tune rules to your traffic, and keep policies fresh with automated updates, a WAF delivers high-impact security with low friction. Combined with secure development and strong observability, it becomes a cornerstone of modern web application and API security.

    Related reading