-
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): testing fixes and rule improvements (#173)
- Loading branch information
Showing
40 changed files
with
2,133 additions
and
415 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,60 @@ | ||
patterns: | ||
- pattern: echo $<EXCEPTION_DETAILS> | ||
filters: | ||
- variable: EXCEPTION_DETAILS | ||
detection: php_lang_information_leakage_exception_details | ||
scope: result | ||
- pattern: print $<EXCEPTION_DETAILS>; | ||
filters: | ||
- variable: EXCEPTION_DETAILS | ||
detection: php_lang_information_leakage_exception_details | ||
scope: result | ||
- pattern: print_r($<EXCEPTION_DETAILS>) | ||
filters: | ||
- variable: EXCEPTION_DETAILS | ||
detection: php_lang_information_leakage_exception_details | ||
scope: result | ||
- pattern: $<METHOD>($<_>, $<...>$<EXCEPTION_DETAILS>$<...>) | ||
filters: | ||
- variable: METHOD | ||
values: | ||
- printf | ||
- vprintf | ||
- variable: EXCEPTION_DETAILS | ||
detection: php_lang_information_leakage_exception_details | ||
scope: result | ||
auxiliary: | ||
- id: php_lang_information_leakage_exception_details | ||
patterns: | ||
- try {} catch ($<_> $<!>$$<_>) {} | ||
- pattern: $<EXCEPTION>->$<_>() | ||
filters: | ||
- variable: EXCEPTION | ||
detection: php_lang_information_leakage_exception_details | ||
scope: cursor | ||
languages: | ||
- php | ||
severity: warning | ||
metadata: | ||
description: Possible information leakage detected. | ||
remediation_message: | | ||
## Description | ||
Printing an exception message to the default output is risky because it may | ||
contain sensitive information such as the technical details of your | ||
application or environment (which in turn could expose your application to | ||
path traversal attacks, for example), or worse, user-specific data. | ||
## Remediations | ||
❌ Avoid printing the full stack trace | ||
✅ Less is more! Only log the minimum required details in error messages | ||
## Resources | ||
- [Web Application Security Consortium: Information Leakage](http://projects.webappsec.org/w/page/13246936/Information%20Leakage) | ||
cwe_id: | ||
- 209 | ||
id: php_lang_information_leakage | ||
documentation_url: https://docs.bearer.com/reference/rules/php_lang_information_leakage |
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,92 @@ | ||
imports: | ||
- php_shared_lang_datatype | ||
patterns: | ||
- pattern: | | ||
md5($<DATA_TYPE>$<...>) | ||
filters: | ||
- either: | ||
- variable: DATA_TYPE | ||
detection: php_shared_lang_datatype | ||
scope: result | ||
- not: | ||
variable: DATA_TYPE | ||
detection: php_shared_lang_datatype | ||
scope: result | ||
- pattern: | | ||
$<FUNCTION>($<ALGORITHM>, $<DATA_TYPE>$<...>) | ||
filters: | ||
- variable: FUNCTION | ||
values: | ||
- hash | ||
- hash_hmac | ||
- variable: ALGORITHM | ||
string_regex: md\d | ||
- either: | ||
- variable: DATA_TYPE | ||
detection: php_shared_lang_datatype | ||
scope: result | ||
- not: | ||
variable: DATA_TYPE | ||
detection: php_shared_lang_datatype | ||
scope: result | ||
- pattern: md5_file(); | ||
- pattern: hash_update($<CONTEXT>, $<DATA_TYPE>) | ||
filters: | ||
- variable: CONTEXT | ||
detection: php_lang_weak_hash_md_context | ||
scope: cursor | ||
- either: | ||
- variable: DATA_TYPE | ||
detection: php_shared_lang_datatype | ||
scope: result | ||
- not: | ||
variable: DATA_TYPE | ||
detection: php_shared_lang_datatype | ||
scope: result | ||
- pattern: $<FUNCTION>($<CONTEXT>$<...>) | ||
filters: | ||
- variable: FUNCTION | ||
values: | ||
- hash_update_file | ||
- hash_update_stream | ||
- variable: CONTEXT | ||
detection: php_lang_weak_hash_md_context | ||
scope: cursor | ||
auxiliary: | ||
- id: php_lang_weak_hash_md_context | ||
patterns: | ||
- pattern: hash_init($<ALGORITHM>$<...>) | ||
filters: | ||
- variable: ALGORITHM | ||
string_regex: md\d | ||
languages: | ||
- php | ||
skip_data_types: | ||
- "Unique Identifier" | ||
- Passwords # see php_lang_weak_password_hash_md5 | ||
metadata: | ||
description: "Weak hashing library (MDx) detected" | ||
remediation_message: | | ||
## Description | ||
A weak hashing library can lead to data breaches and greater security risk. | ||
## Remediations | ||
According to [OWASP](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/09-Testing_for_Weak_Cryptography/04-Testing_for_Weak_Encryption), MD5 is considered a weak hashing algorithms and therefore shouldn't be used. | ||
❌ Avoid libraries and algorithms with known weaknesses: | ||
```php | ||
$encrypted = md5($input) | ||
``` | ||
✅ Use stronger encryption algorithms when storing data. | ||
```php | ||
$encrypted = hash('sha256', $input) | ||
``` | ||
cwe_id: | ||
- 327 | ||
id: php_lang_weak_hash_md | ||
documentation_url: https://docs.bearer.com/reference/rules/php_lang_weak_hash_md |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.