Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Extending Symfony2 Web Application Framework

You're reading from   Extending Symfony2 Web Application Framework Symfony2 took the great features of the original framework to new levels of extensibility. With this practical guide you'll learn how to make the most of Symfony2 through controlling your code and sharing it more widely.

Arrow left icon
Product type Paperback
Published in Mar 2014
Publisher
ISBN-13 9781783287192
Length 140 pages
Edition Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sebastien Armand Sebastien Armand
Author Profile Icon Sebastien Armand
Sebastien Armand
Arrow right icon
View More author details
Toc

Securing an API – an example


It is becoming a common practice to only have an API on your web server and not generate the page's HTML on the server but through JavaScript in a user's browser.

However, it is also common for developers to still use standard sessions and logins when the API is only there to serve their own website at first. This can lead to issues regarding security. Whenever you create a form to be displayed in Symfony via Twig, it contains a CSRF token. This token is here to help us ensure that not only is the request coming from this user's browser (cookies do that) but also from your actual webpage and not a malicious tab in the user's browser.

With an API, your forms are going to be generated entirely in the frontend. So, they cannot include a CSRF token. Furthermore, whenever an attacker submits a request to our server through a user's browser, all the cookies will be sent together, allowing the attacker to control the user's account. However, because of the same origin...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image