Security advanced

Contents
Remember-me
2FA concept
Reuse voters
Log security events

Remember-me

Remember me keeps users logged in across browser restarts with a long lived cookie. It is config text, not code in controllers.

Keep the lifetime short and refresh it on real logins. Treat the cookie like a spare key, not a master key.

2FA concept

Two factor adds a second proof after the password, often a short code from a phone app. The password alone stops working for attackers.

Ask for the code on login and on sensitive actions. Offer backup codes for lost phones.

Reuse voters

Reuse the voters from the security lesson for row level rules. One voter answers who may edit or view each object.

The sketch below grants one action by name. Real voters also check owners and roles.

use Symfony\Component\Security\Core\Authorization\Voter\Voter; class PostVoter extends Voter { protected function supports(string $attribute, mixed $subject): bool { return $attribute === "EDIT"; } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool { // owner wins return true; } }

Log security events

Log who did what on guarded actions: logins, failed tries, grants, and denies. Logs turn strange spikes into clear stories.

Write one line per event with who, what, and when. Read the log first when a user reports a block.

function auditLogin($log, string $who): void { $log->info("Login ok for " . $who); }

Next: HTTP client

Article author: Arthur Isaev

Related articles
Development with PHP
What is Symfony and where it runs
Install Symfony
Your first page
Routes
Controllers
Twig basics
Twig advanced
Doctrine setup
Entities
Migrations
Repositories
Relations
Forms
Validation
Services and DI
JSON controllers
Serializer
Security intro
Users
Login form
Voters
Console commands
Events
Messenger
Mailer
Cache
Sessions
CSRF
Translations
Dotenv and env
Profiler
Testing
Fixtures
Pagination
File uploads
API Platform in one lesson
DQL
Transactions
Migrations advanced
Security advanced
HTTP client
Scheduler
Webhooks
Asset Mapper
Deployment
Performance
Capstone: blog
Capstone: JSON API
Modern Symfony tour
Hero roadmap: the whole course on one page

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: