Web3 Builders

Security Headers and Web Security for dApps

How dApp teams can harden their websites with security headers, content security policy, dependency controls and hosting settings that reduce frontend attack risk.

Browser window protected by layered transparent shields

Smart contract audits get most of the security attention in crypto, but many user losses happen through the website. A compromised frontend can show fake contract addresses, alter transaction data or inject a wallet drainer, even when the contracts themselves are perfect. Hardening the frontend is part of protecting users.

Why frontends are targets

Attackers go after dApp frontends through:

  • Compromised third-party scripts, such as analytics or chat widgets
  • Malicious package updates in the build pipeline
  • DNS or hosting account takeovers
  • Cross-site scripting through unescaped user content
  • Clickjacking, where the site is embedded invisibly in another page

Each path lets attackers change what users see and sign.

Content Security Policy

A Content Security Policy tells browsers which sources are allowed to load scripts, styles, images and connections. A strict policy blocks injected scripts from unknown domains.

A starting point for a dApp might allow:

Directive Typical setting
default-src Own domain only
script-src Own domain, no inline scripts where possible
connect-src Own API plus specific RPC and wallet connection endpoints
img-src Own domain, data URIs if needed
frame-ancestors None, to prevent embedding
form-action Own domain

Build the policy gradually. Start in report-only mode, review violations, then enforce.

Other important headers

Several headers add protection with little effort:

  1. Strict-Transport-Security forces HTTPS for future visits
  2. X-Content-Type-Options: nosniff prevents browsers from guessing file types
  3. X-Frame-Options: DENY or frame-ancestors in CSP blocks clickjacking
  4. Referrer-Policy limits information shared with other sites
  5. Permissions-Policy disables browser features the site does not need, such as camera or microphone

Most hosting platforms let you set headers in a configuration file.

Control dependencies

Frontend builds pull in hundreds of packages. Reduce risk:

  • Lock dependency versions with a lockfile
  • Review changes when updating packages, especially wallet and crypto libraries
  • Remove unused dependencies
  • Prefer well-maintained libraries with active security response
  • Use automated alerts for known vulnerabilities

Avoid loading critical libraries from public CDNs without integrity checks. Self-hosting scripts or using subresource integrity hashes prevents silent changes.

Package box inspected by a magnifying glass with a checkmark
Every third-party script is code you are trusting with users' wallets.

Minimise third-party scripts

Every analytics tag, chat widget or marketing pixel runs code with the same access as your app. Ask whether each script is necessary. For privacy and security, many crypto teams use minimal, self-hosted analytics or none at all.

Escape user content

If your dApp displays user-generated content, such as profile names, comments or token metadata, escape it properly. Token names and NFT metadata can contain malicious strings designed to exploit interfaces that render them as HTML.

Secure the hosting and deployment

  • Protect hosting and DNS accounts with hardware security keys
  • Limit who can deploy to production
  • Use signed commits or protected branches for release code
  • Monitor deployments for unexpected changes
  • Keep a known-good build ready for fast rollback

Show addresses users can verify

Display full contract addresses in the interface and link them to block explorers. Encourage users to compare addresses with official documentation. If a compromised frontend alters addresses, users who check have a chance to notice.

Frontend security is stronger when users can verify links independently. Keep official domains and contract addresses consistent across your docs, social accounts and public profiles such as a Proud Globe pin. Proud Globe itself serves strict security headers on every page and loads no third-party tracking scripts.

Educational content only. Nothing here is financial, legal or tax advice. Crypto assets carry risk, so check the details for your own situation.