-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[WIP][RFC] Signed internal uris #6463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
53ae654
Revert "[TwigBundle] added a compatibility layer for the render tag s…
asm89 38dc327
Revert "[FrameworkBundle] restricted to only URIs the first argument …
asm89 d4d4973
Revert "restricted to only URIs the first argument of the render tag"
asm89 a564c1e
[WIP][RFC] Keep 'old' render behavior. Sign _internal urls instead.
asm89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Controller; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerAware; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* InternalController. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class InternalController extends ContainerAware | ||
{ | ||
/** | ||
* Forwards to the given controller with the given path. | ||
* | ||
* @param string $path The path | ||
* @param string $controller The controller name | ||
* | ||
* @return Response A Response instance | ||
*/ | ||
public function indexAction($path, $controller) | ||
{ | ||
// safeguard | ||
if (!is_string($controller)) { | ||
throw new \RuntimeException('A Controller must be a string.'); | ||
} | ||
|
||
// check that the controller looks like a controller | ||
if (false === strpos($controller, '::')) { | ||
$count = substr_count($controller, ':'); | ||
if (2 == $count) { | ||
// the convention already enforces the Controller suffix | ||
} elseif (1 == $count) { | ||
// controller in the service:method notation | ||
list($service, $method) = explode(':', $controller, 2); | ||
$class = get_class($this->container->get($service)); | ||
|
||
if (!preg_match('/Controller$/', $class)) { | ||
throw new \RuntimeException('A Controller class name must end with Controller.'); | ||
} | ||
} else { | ||
throw new \LogicException('Unable to parse the Controller name.'); | ||
} | ||
} else { | ||
list($class, $method) = explode('::', $controller, 2); | ||
|
||
if (!preg_match('/Controller$/', $class)) { | ||
throw new \RuntimeException('A Controller class name must end with Controller.'); | ||
} | ||
} | ||
|
||
$request = $this->container->get('request'); | ||
|
||
if (!$this->container->get('routing.url_signer')->verify($request->getUri())) { | ||
throw new \RuntimeException('Invalid url signature.'); | ||
} | ||
|
||
$attributes = $request->attributes; | ||
|
||
$attributes->remove('path'); | ||
$attributes->remove('controller'); | ||
if ('none' !== $path) { | ||
parse_str($path, $tmp); | ||
$attributes->add($tmp); | ||
} | ||
|
||
return $this->container->get('http_kernel')->forward($controller, $attributes->all(), $request->query->all()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<routes xmlns="http://symfony.com/schema/routing" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> | ||
|
||
<route id="_internal" pattern="/secure/{controller}/{path}.{_format}"> | ||
<default key="_controller">FrameworkBundle:Internal:index</default> | ||
<requirement key="path">.+</requirement> | ||
<requirement key="_format">[^.]+</requirement> | ||
</route> | ||
|
||
<route id="_internal_public" pattern="/{controller}/{path}.{_format}"> | ||
<default key="_controller">FrameworkBundle:Internal:index</default> | ||
<requirement key="path">.+</requirement> | ||
<requirement key="_format">[^.]+</requirement> | ||
</route> | ||
</routes> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Routing; | ||
|
||
/** | ||
* Signs and verifies signed urls. | ||
* | ||
* @author Alexander <iam.asm89@gmail.com> | ||
*/ | ||
class UrlSigner | ||
{ | ||
private $secret; | ||
|
||
/** | ||
* @param string $secret | ||
*/ | ||
public function __construct($secret) | ||
{ | ||
$this->secret = $secret; | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* | ||
* @return string Signed url. | ||
*/ | ||
public function sign($url) | ||
{ | ||
// todo: actually sign the url | ||
return $url; | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* | ||
* @return boolean | ||
*/ | ||
public function verify($url) | ||
{ | ||
// todo: actually verify the signed url | ||
return true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is the convention, but why must it be a hard requirement? (Maybe it already is in full stack, not sure.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using direct controllers is not supported at all in 2.2. This change allows to limit the security issue by allowing to execute code only in controllers (as this feature cannot be removed in maintenance release)