How to secure FCKEditor against unauthorized access in a Symfony application

So you’ve managed to integrate FCKEditor into Symfony for use with your administrative console.

Problem: FCKEditor has a file uploader for media files.  Images, documents, Flash files, that sort of thing.  It’s run off a PHP connector.

All that a hacker needs to do is enter a URL like so:

/js/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=../../connectors/php/connector.php

…and he or she is able to upload media files.

You’ve secured your application using security.yml, and perhaps the sfGuard plugin.  But what about that file uploader?  It isn’t launched by one of your controllers.  It has its own.

Solution: Turn the PHP connector in FCKEditor into a controller.

1.  Open up the PHP connector’s config.php at:

web/js/fckeditor/editor/filemanager/connectors/php/config.php

2.  Turn it into a Symfony controller.  Insert the following at the top of the file:

define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/../../../../../../..'));
define('SF_APP',         'backend');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG',       false);

require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

if ( !sfContext::getInstance()->getUser()->isAuthenticated() ) {
  exit();
}

Make sure you enter the correct SF_APP, and a relative path to SF_ROOT_DIR.

If the user isn’t authenticated, I simply exit.  The reason I don’t redirect to a nice “session timed out” page is because the PHP is called from FCKEditor’s Javascript.  If anyone has a more elegant solution, please comment!

2 Comments

  1. geoffrey
    Posted August 7, 2009 at 1:16 pm | Permalink

    hello,

    What do you mean witch SF_APP and SF_ROOT_DIR. Wich path is this ?

    • jjmontgo
      Posted August 7, 2009 at 2:48 pm | Permalink

      Hi Geoffrey.

      In the code excerpt above where these two constants are mentioned, you’ll see them defined.

      SF_APP is the name of your application, and SF_ROOT_DIR is the directory of your Symfony application.

      These two constants are defined in every Symfony 1.0 controller file (ie. index.php).


Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*