How would you secure a slug in Symfony2.1?
A malicious user could append ";rm -rf *"
to the id value and delete the entire Website. In symfony2.1, is there a simple way to secure the slugs?
I have tried to secure an id this way.
/**
* The idea is to check that the slug cart_id is an id and not
*
* @Route("/{cart_id}/show", name="show_cart")
* @Template()
*/
public function showCartAction($cart_id)
{
if (!preg_match("/^[0-9]{2}$/", $cart_id))
{
throw new \Exception("the id is not correct");
}
$cart = $this->getCartManager()
->getCart($cart_id);
return array(
'cart'=> cart
);
}
Do you find this necessary? Would you do it this way ?