Skip to content

Commit

Permalink
fix csrf problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroennoten committed Aug 16, 2016
1 parent f4a0366 commit c01764b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 53 deletions.
11 changes: 6 additions & 5 deletions src/CkEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@

use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Contracts\View\Factory;
use Illuminate\Session\Store;

class CkEditor
{
private $view;

private $url;

private $session;
private $instanceCount = 0;

public function __construct(Factory $view, UrlGenerator $url)
public function __construct(Factory $view, UrlGenerator $url, Store $session)
{
$this->view = $view;
$this->url = $url;
$this->session = $session;
}

public function editor($name = null, $config = null)
Expand All @@ -31,8 +32,8 @@ public function editor($name = null, $config = null)
private function config()
{
return [
'filebrowserImageUploadUrl' => $this->url->route('ckeditor.images.store'),
'uploadUrl' => $this->url->route('ckeditor.images.store', 'json'),
'filebrowserImageUploadUrl' => $this->url->route('ckeditor.images.store', ['_token' => $this->session->token()]),
'uploadUrl' => $this->url->route('ckeditor.images.store', ['json', '_token' => $this->session->token()]),
'extraPlugins' => 'uploadimage'
];
}
Expand Down
34 changes: 0 additions & 34 deletions src/Http/Middleware/VerifyCsrfToken.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function registerRoutes(Router $router)
$router->group([
'prefix' => 'ckeditor',
'as' => 'ckeditor.',
'middleware' => ['api', StartSession::class, 'auth', VerifyCsrfToken::class],
'middleware' => ['web', 'auth'],
'namespace' => __NAMESPACE__ . '\\Http\\Controllers'
], function (Router $router) {

Expand Down
13 changes: 0 additions & 13 deletions tests/ImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ public function testJsonUpload(UrlGenerator $urlGenerator)
]);
}

/**
* @param UrlGenerator $urlGenerator
* @expectedException \Illuminate\Session\TokenMismatchException
*/
public function testCsrf(UrlGenerator $urlGenerator)
{
$this->actingAs(new User);

$this->upload($urlGenerator->route('ckeditor.images.store', [
'CKEditorFuncNum' => 9
]), 0, false);
}

public function testAuth(UrlGenerator $urlGenerator)
{
$this->upload($urlGenerator->route('ckeditor.images.store', [
Expand Down

0 comments on commit c01764b

Please sign in to comment.