RepositoryPHPCHSwitzerland
NE

nelmio/NelmioSecurityBundle

Adds extra security-related features in your Symfony application

681stars
92forks
27issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: xss

#1 Repository of the month

1
TINIX TRENDING·Topic: hsts

#1 Repository of the month

1
TINIX TRENDING·Topic: csp

#1 Repository of the month

NelmioSecurityBundle

About

The NelmioSecurityBundle provides additional security features for your Symfony application.

Installation

Require the nelmio/security-bundle package in your composer.json and update your dependencies:

composer require nelmio/security-bundle

The bundle should be automatically enabled by Symfony Flex. If you don't use Flex, you'll need to enable it manually as explained in the docs.

Features

Read the docs for the details and configuration needed for each feature:

  • Content Security Policy: Cross site scripting attacks (XSS) can be mitigated in modern browsers using a policy which instructs the browser never to execute inline scripts, or never to load content from another domain than the page's domain.

  • Signed Cookies: Specify certain cookies to be signed, so that the user cannot modify them. Note that they will not be encrypted, but signed only. The contents will still be visible to the user.

  • Clickjacking Protection: X-Frame-Options header is added to all responses to prevent your site from being put in a frame/iframe. This can have serious security implications as it has been demonstrated time and time again with Facebook and others. You can allow framing of your site from itself or from anywhere on a per-URL basis.

  • External Redirects Detection: Redirecting from your site to arbitrary URLs based on user input can be exploited to confuse users into clicking links that seemingly point to valid sites while they in fact lead to malicious content. It also may be possible to gain PageRank that way.

  • Forced HTTPS/SSL Handling: This forces all requests to go through SSL. It will also send HSTS headers so that modern browsers supporting it can make users use HTTPS even if they enter URLs without https, avoiding attacks on public Wi-Fi.

  • Flexible HTTPS/SSL Handling: If you don't want to force all users to use HTTPS, you should at least use secure session cookies and force SSL for logged-in users. But then logged-in users appear logged-out when they access a non-HTTPS resource. This is not really a good solution. This will make the application detect logged-in users and redirect them to a secure URL, without making the session cookie insecure.

  • Disable Content Type Sniffing: Require that scripts are loaded using the correct mime type. This disables the feature that some browsers have which uses content sniffing to determine if the response is a valid script file or not.

  • (DEPRECATED) XSS Protection: Enables/Disables Microsoft XSS Protection on compatible browsers (IE 8 and newer).

  • Referrer Policy: Referrer-Policy header is added to all responses to control the Referer header that is added to requests made from your site, and for navigations away from your site by browsers.

Testing

The bundle provides PHPUnit assertions to test security headers in your application. See TESTING.md for details.

Usage

See the documentation for usage instructions.

License

Released under the MIT License, see LICENSE.

Similar Projects

Discover other similar projects and AI models.

RepositoryPHP
symfony/symfony

The Symfony PHP framework

31.5k
Nov 29, 2026
RepositoryPHP
getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony

15.8k
Nov 30, 2026
RepositoryPHP
doctrine/DoctrineBundle

Symfony Bundle for Doctrine ORM and DBAL

4.8k
Dec 1, 2026
RepositoryPHP
EasyCorp/EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.

4.3k
Nov 28, 2026
RepositoryPHP
doctrine/DoctrineMigrationsBundle

Symfony integration for the doctrine/migrations library

4.3k
Nov 16, 2026
RepositoryPHP
sensiolabs/SensioFrameworkExtraBundle

An extension to Symfony FrameworkBundle that adds annotation configuration for Controller classes

3.3k
Feb 24, 2023
RepositoryPHP
aidantwoods/SecureHeaders

A PHP library aiming to make the use of browser security features more accessible.

429
Nov 17, 2023
RepositoryGo
chaitin/SafeLine

SafeLine is a self-hosted WAF(Web Application Firewall) / reverse proxy to protect your web apps from attacks and exploits.

23.5k
Nov 23, 2026
RepositoryRuby
github/secure_headers

Manages application of security headers with many safe defaults

3.2k
Nov 25, 2026