PHP and Symfony6 min

Symfony security best practices and audit tools in 2026

Par Pierre-Arthur Demengel
SymfonyCode auditPHPStan
Partager

The Symfony official documentation gives you the core of a code audit: its security guide and best practices cover firewalls, voters, and secrets, the profiler helps you diagnose in development only, and the testing guide defines three levels of tests. PHPStan, a separate tool, adds static analysis across 11 strictness levels. In 2026, the job of an audit is to combine these tools with human review, because no tool can tell you whether your business permissions are correct.

I sell application development and takeover work, so I have an interest in this topic. Everything below can still be run by your own team, using free documentation and tools.

Symfony security best practices: what to check first

Start with the Symfony best practices page, which describes itself as a good starting point rather than a set of strict rules. On security, it recommends a single firewall unless you really have two different authentication systems, the auto password hasher, and custom voters when security logic becomes complex. For configuration, it separates environment variables for infrastructure settings from sensitive values such as API keys, which belong in Symfony's secrets management system.

The security guide explains two details that auditors should test rather than assume. Only one firewall is active per request, chosen as the first pattern that matches. In access_control too, Symfony stops at the first matching rule, so the order of the rules changes what is protected. The guide also notes that the login form is not protected against CSRF (a forged request sent from another site) until you enable it.

A permission that depends on who owns a record cannot be expressed by a route rule alone. Voters centralize this logic, and they are where I would look first: can customer A open the invoice of customer B by changing a number in the URL? A scanner will rarely find that for you, whereas one targeted test will.

The Symfony profiler: useful, and dangerous in production

The profiler documentation is unusually blunt. It says you should never enable the profiler in production, because doing so leads to major security vulnerabilities. So an audit should include a simple check of the live environment: is /_profiler reachable, and does the deployment install development dependencies?

Used in development, the profiler is a diagnostic tool. It lets a reviewer inspect what happens on any request and open the collected data through the debug toolbar. This makes it useful for understanding unfamiliar code, particularly on an application without documentation.

Testing and PHPStan: what each audit tool actually proves

The testing guide distinguishes unit tests, integration tests and application tests, all run with PHPUnit. On a project with no tests, the best practices page offers a cheap first step: a smoke test that loads a list of URLs and checks that they respond successfully. It will not prove that your business rules work, but it can stop an obviously broken release.

PHPStan reads the code without running it. Its levels go from 0, the loosest, to 10, the strictest, and each one includes the checks of those below it. The level number alone says little, so ask what was excluded from the analysis too.

ToolWhat it can revealWhat it cannot tell you
composer auditKnown security advisories, abandoned packages and packages flagged as malwareFlaws in your own code
symfony check:securityKnown vulnerabilities, checked locally against public advisoriesWhether the vulnerable code path is actually used
PHPStanType errors, unknown methods, unsafe assumptionsWhether the business logic is right
PHPUnitWhether the tested behavior still worksAnything that is not tested
ProfilerWhat a request does in developmentProduction behavior under real load
Human reviewPermissions, architecture, risky shortcutsEverything, within limited time

For dependency checks, the Symfony setup guide describes symfony check:security, then recommends composer audit in continuous integration, because it needs no Symfony CLI and reports more vulnerabilities. Composer's documentation adds that the command also detects abandoned packages and those flagged as malware.

Check your versions before anything else in 2026

A clean audit of an unsupported stack is still a risk. According to the Symfony release page, as read on November 1, 2026, version 8.1 is supported until January 2027, while the long term support version 7.4 receives bug fixes until November 2028 and security fixes until November 2029. Version 6.4 gets bug fixes until November 2026 and security fixes until November 2027. On the PHP side, PHP 8.2 security support ends on December 31, 2026. If you need to move up a major version, the upgrade guide asks you to clear deprecations first, and mentions Rector for automating some of those fixes.

When to hire an auditor, and when not to

Your team may not need outside help. If it already runs these tools in continuous integration, reviews its own permissions and keeps its versions current, an external audit may add little unless a client or an insurer asks for one. A dedicated penetration test is also a different service: it attacks the running application, and a security specialist is the better fit if that is what you need.

An outside view helps most when the original developers have left, when nobody dares upgrade, or before a significant investment. When you request a proposal, ask what will be read by a person rather than a tool, which versions and environments are covered, how findings are ranked, and whether you can pass the report to another developer. Ask anyone, including me, for an example that matches your situation.

I am an independent developer based in Metz, France, and I work on Symfony, PHP and API Platform applications, including takeovers. You speak directly with the person who reads the code. See my web application services or send your versions and your concern through the contact page. I do not publish prices, and I reply within 24 business hours.

Questions fréquentes

Partager
13 projets livrésGrand-Est & BelgiqueLighthouse >90Disponible immédiatement

Un projet en tête ?

Discutons de votre site web. Réponse garantie sous 24h.

Ou appelez directement :06 95 41 30 25