8000 [Security][CSRF] Double Submit Cookies CSRF prevention strategy by backbone87 · Pull Request #18333 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security][CSRF] Double Submit Cookies CSRF prevention strategy #18333

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
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
add a secureNamespace to SessionTokenStorageFactory for secure requests
  • Loading branch information
backbone87 committed Sep 21, 2016
commit a533b0e45e0a7e0573f4d72978adb692be7d448d
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ class SessionTokenStorageFactory implements TokenStorageFactoryInterface
private $namespace;

/**
* @param string $namespace The namespace under which the token is stored in the session
* @var string
*/
public function __construct($namespace = null)
private $secureNamespace;

/**
* @param string $namespace The namespace under which tokens are stored in the session
* @param string $secureNamespace The namespace under which tokens are stored in the session for secure connections
*/
public function __construct($namespace = null, $secureNamespace = null)
{
$this->namespace = $namespace === null ? SessionTokenStorage::SESSION_NAMESPACE : (string) $namespace;
$this->secureNamespace = $secureNamespace === null ? $this->namespace : (string) $secureNamespace;
}

/**
Expand All @@ -44,6 +51,8 @@ public function createTokenStorage(Request $request)
throw new RuntimeException('Request has no session');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could modify the namespace here, to use a different one for SSL connections, because tokens transmitted via non SSL connections are subject to MITM attacks.

return new SessionTokenStorage($session, $this->namespace);
$namespace = $request->isSecure() ? $this->secureNamespace : $this->namespace;

return new SessionTokenStorage($session, $namespace);
}
}
0