-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(php/symphony): split insecure cookie rule
- Loading branch information
Showing
6 changed files
with
176 additions
and
308 deletions.
There are no files selected for viewing
This file contains 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,87 @@ | ||
imports: | ||
- php_shared_lang_instance | ||
patterns: | ||
- pattern: | | ||
$<CLASS>::create($<_>, $<_>, $<_>, $<_>, $<_>, $<_>, $<HTTP_ONLY>$<...>) | ||
filters: | ||
- variable: CLASS | ||
regex: \A(\\?Symfony\\Component\\HttpFoundation\\)?Cookie\z | ||
- variable: HTTP_ONLY | ||
detection: php_symfony_cookie_missing_http_only_false | ||
scope: cursor | ||
- pattern: | | ||
$<CLASS>::create(httpOnly: $<HTTP_ONLY>) | ||
filters: | ||
- variable: CLASS | ||
regex: \A(\\?Symfony\\Component\\HttpFoundation\\)?Cookie\z | ||
- variable: HTTP_ONLY | ||
detection: php_symfony_cookie_missing_http_only_false | ||
scope: cursor | ||
- pattern: | | ||
new $<CLASS>($<_>, $<_>, $<_>, $<_>, $<_>, $<_>, $<HTTP_ONLY>$<...>) | ||
filters: | ||
- variable: CLASS | ||
regex: \A(\\?Symfony\\Component\\HttpFoundation\\)?Cookie\z | ||
- variable: HTTP_ONLY | ||
detection: php_symfony_cookie_missing_http_only_false | ||
scope: cursor | ||
- pattern: | | ||
new $<CLASS>(httpOnly: $<HTTP_ONLY>) | ||
filters: | ||
- variable: CLASS | ||
regex: \A(\\?Symfony\\Component\\HttpFoundation\\)?Cookie\z | ||
- variable: HTTP_ONLY | ||
detection: php_symfony_cookie_missing_http_only_false | ||
scope: cursor | ||
- pattern: $<COOKIE>->withHttpOnly($<HTTP_ONLY>) | ||
filters: | ||
- variable: COOKIE | ||
detection: php_symfony_cookie_missing_http_only_instance | ||
scope: cursor | ||
- variable: HTTP_ONLY | ||
detection: php_symfony_cookie_missing_http_only_false | ||
scope: cursor | ||
auxiliary: | ||
- id: php_symfony_cookie_missing_http_only_false | ||
patterns: | ||
- "false;" | ||
- id: php_symfony_cookie_missing_http_only_instance | ||
patterns: | ||
- pattern: $<INSTANCE>; | ||
filters: | ||
- variable: INSTANCE | ||
detection: php_shared_lang_instance | ||
scope: cursor | ||
filters: | ||
- variable: CLASS | ||
regex: \A(\\?Symfony\\Component\\HttpFoundation\\)?Cookie\z | ||
- pattern: | | ||
$<CLASS>::create() | ||
filters: | ||
- variable: CLASS | ||
regex: \A(\\?Symfony\\Component\\HttpFoundation\\)?Cookie\z | ||
- pattern: $<COOKIE>->$<_>() | ||
filters: | ||
- variable: COOKIE | ||
detection: php_symfony_cookie_missing_http_only_instance | ||
scope: cursor | ||
languages: | ||
- php | ||
metadata: | ||
description: "Missing 'HTTPOnly' options in cookie configuration." | ||
remediation_message: | | ||
## Description | ||
The "HttpOnly" attribute when set to "true" protects the cookie value from | ||
being accessed by client side JavaScript such as reading the "document.cookie" | ||
values. By enabling this protection, a website that is vulnerable to Cross-Site | ||
Scripting (XSS) will be able to block malicious scripts from accessing the | ||
cookie value from JavaScript. | ||
## Remediations | ||
✅ Set `httpOnly` to `true` to avoid the cookie being sent by client-side scripts. | ||
cwe_id: | ||
- 1004 | ||
id: php_symfony_cookie_missing_http_only | ||
documentation_url: https://docs.bearer.com/reference/rules/php_symfony_cookie_missing_http_only | ||
cloud_code_suggestions: true |
This file contains 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 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 @@ | ||
const { | ||
createNewInvoker, | ||
getEnvironment, | ||
} = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
|
||
describe(ruleId, () => { | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase) | ||
|
||
test("cookie_missing_http_only", () => { | ||
const testCase = "index.php" | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
tests/php/symfony/cookie_missing_http_only/testdata/index.php
This file contains 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,26 @@ | ||
// Use bearer:expected php_symfony_cookie_missing_http_only to flag expected findings | ||
|
||
<?php | ||
|
||
use Symfony\Component\HttpFoundation\Cookie; | ||
|
||
Cookie::create($name, $value, $expire, $path, $domain, false, $httpOnly); | ||
// bearer:expected php_symfony_cookie_missing_http_only | ||
Cookie::create($name, $value, $expire, $path, $domain, $secure, false, $raw); | ||
// bearer:expected php_symfony_cookie_missing_http_only | ||
Cookie::create($name, $value, httpOnly: false); | ||
|
||
$cookie = Cookie::create($name, $value); | ||
// bearer:expected php_symfony_cookie_missing_http_only | ||
$cookie->withRaw(false)->withHttpOnly(false); | ||
|
||
new Cookie($name, $value, secure: false); | ||
// bearer:expected php_symfony_cookie_missing_http_only | ||
new Cookie($name, $value, $expire, $path, $domain, $secure, false, $raw); | ||
// bearer:expected php_symfony_cookie_missing_http_only | ||
new Cookie($name, $value, httpOnly: false); | ||
|
||
$cookie = new Cookie($name, $value); | ||
$cookie->withRaw(false)->withSecure(false); | ||
// bearer:expected php_symfony_cookie_missing_http_only | ||
$cookie->withRaw(false)->withHttpOnly(false); |
Oops, something went wrong.