Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php frameworks and security

As a web developer I am using PHP and I know that I have to worry about security but when you use a framework, there is a lot-of code and design that you relay on but that you didn't code or design and for instance I am using CakePHP.

  • so in this case with frameworks how much should i worry about security ?
like image 432
Ayoub M. Avatar asked Sep 03 '09 10:09

Ayoub M.


People also ask

Which PHP framework is most secure?

PHP frameworks: Yii Moreover, it is one of the most secure PHP frameworks with powerful features like encryption, password hashing, authentication, and authorization. Therefore, developers can easily customize every part of code and build highly secure projects with this framework.

What is PHP and its frameworks?

What is a PHP framework? A PHP framework is a platform to build PHP web applications. PHP frameworks provide libraries for commonly used functions, which helps to cut down on the amount of original code developers need to write from scratch.

Which is best framework of PHP and why?

Laravel – a popular PHP web framework with great extendability for high-quality applications. CodeIgniter – one of the most popular PHP frameworks with MVC support, great for creating lightweight web applications. Symfony – a modular PHP framework with a built-in debugging system and extensive documentation.


2 Answers

You should always continue respecting the basic principles of security :

  • don't trust the user
  • never trust the user

Which kinda means :

  • filter / validate everything that comes to your application
  • escape any output.


Using a framework doesn't change much about that, except that :

  • Output to the database often es some layer of the framework, which should deal with escaping
  • Frameworks often provide filtering / validation solutions ; use them ;-)
  • Frameworks often have some guidelines ; read them.


As a sidenote : you said this :

there is a lot-of code and design that you relay on but that you didn't code or design

Considering you are using a well-known framework that lots of people use, this code has probably been more tested/reviewed than any code you could write ;-)

That's an advantage of open-source, actually : you are not the only one responsible for the code, and lots of eyes have seen it -- which means lots of hands have enhanced it.

like image 58
Pascal MARTIN Avatar answered Oct 30 '22 21:10

Pascal MARTIN


There are a lot of things to consider when dealing with security in an application. As Pascal said, it is a good idea to use a popular framework that has had a number of people looking at it.

I see a few areas of concern in regards to CakePHP.

The first issue is the end user. You should expect someone to do something foolish on every page you build. Some examples of this are:

  • A person clicking the submit button rapidly over and over. This may skew or mess up your system in a way if you're not careful. The solution for this is not based on the framework, but rather your coding methodology and testing.
  • SQL Injection and other bad things. Any field on a page can be potentially abused, therefore every form element must be sanitized. CakePHP has simple methods to take care of these security issues. http://book.cakephp.org/view/153/Data-Sanitization
  • Clean URL's are very important. You should never design a system that allows a user to access integer primary keys directly. For instance, if you have a site that has /show_user/2098 then someone can simply type in show_user/2097 to see someone else's account. CakePHP allows you to incorporate slugs or UUID's quite easily, to prevent this from happening.

Second, you must be concerned with attacks dealing with the code and permissions itself. For example:

  • Never use eval() or system() in your code from data that may come from the end user. There have been applications in the past written in perl that have been hijacked because of this issue.
  • The folder structure and permissions is important in regards to security. Users should never have access to get into a writable directory. With CakePHP the folder structure is designed so that you can point apache directly to app/webroot. This means the tmp directory is outside of the apache path, making the system a bit more secure.

Third, you should be concerned with the protection of your administration pages and who has permissions to access what.

  • CakePHP has an Auth and an Acl component that allows you to choose what users get access to which pages. This makes use of custom Cake Sessions which can be stored in a database, by using PHP or written to the file system.

I would suggest reading up on some of the important components and being sure you set them up properly, to ensue you have built an application without security flaws. Take a look at some of these elements as you research further: http://book.cakephp.org/view/170/Core-Components

like image 37
Dooltaz Avatar answered Oct 30 '22 21:10

Dooltaz