-
Notifications
You must be signed in to change notification settings - Fork 1
Semgrep testing 98 #41
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
Open
vivekkhimani
wants to merge
4
commits into
master
Choose a base branch
from
semgrep-testing-98
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import yaml | ||
|
|
||
|
|
||
| yaml.load(Loader=yaml.Loader) | ||
|
|
||
| yaml.unsafe_load("something") | ||
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,46 @@ | ||
| public class ActiveDebugCode{ | ||
|
|
||
| public void bad(){ | ||
| StackTraceElement[] elements; | ||
|
|
||
| Exception e = new Exception(); | ||
| elements = e.getStackTrace(); | ||
|
|
||
| // ruleid: active-debug-code-getstacktrace | ||
| System.err.print(elements); | ||
| } | ||
|
|
||
| public void bad2(){ | ||
| StackTraceElement[] elements; | ||
|
|
||
| elements = Thread.currentThread().getStackTrace(); | ||
|
|
||
| // ruleid: active-debug-code-getstacktrace | ||
| System.err.print(elements); | ||
| } | ||
|
|
||
| public void bad3(){ | ||
| StackTraceElement[] elements; | ||
|
|
||
| elements = new Throwable().getStackTrace(); | ||
|
|
||
| // ruleid: active-debug-code-getstacktrace | ||
| System.err.print(elements); | ||
| } | ||
|
|
||
| public void bad4(){ | ||
| // ruleid: active-debug-code-getstacktrace | ||
| System.out.println(org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e)); | ||
| // ruleid: active-debug-code-getstacktrace | ||
| System.out.println(org.apache.commons.lang3.exception.ExceptionUtils.getFullStackTrace(e)); | ||
| } | ||
|
|
||
| public void alsobad(){ | ||
| for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { | ||
| // ruleid: active-debug-code-getstacktrace | ||
| System.out.println(ste); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
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,71 @@ | ||
| import json | ||
| from json import load, loads | ||
|
|
||
| from http.server import BaseHTTPRequestHandler | ||
| import urllib.parse | ||
|
|
||
| class GetHandler(BaseHTTPRequestHandler): | ||
|
|
||
| def do_GET(self): | ||
| tainted = urlparse.urlparse(self.path).query | ||
|
|
||
| # ruleid: tainted-json | ||
| json.load(tainted) | ||
| # ruleid: tainted-json | ||
| json.load(tainted, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
| # ruleid: tainted-json | ||
| json.loads(tainted) | ||
| # ruleid: tainted-json | ||
| json.loads(tainted, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
|
|
||
| decoder = json.JSONDecoder() | ||
| # ruleid: tainted-json | ||
| decoder.decode(tainted) | ||
| # ruleid: tainted-json | ||
| decoder.raw_decode(tainted) | ||
|
|
||
| # ok: tainted-json | ||
| json.load(s) | ||
| # ok: tainted-json | ||
| json.load(s, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
| # ok: tainted-json | ||
| json.loads(s) | ||
| # ok: tainted-json | ||
| json.loads(s, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
|
|
||
| decoder = json.JSONDecoder() | ||
| # ok: tainted-json | ||
| decoder.decode(s) | ||
| # ok: tainted-json | ||
| decoder.raw_decode(s) | ||
|
|
||
| # ruleid: tainted-json | ||
| load(tainted) | ||
| # ruleid: tainted-json | ||
| load(tainted, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
| # ruleid: tainted-json | ||
| loads(tainted) | ||
| # ruleid: tainted-json | ||
| loads(tainted, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
|
|
||
| decoder = JSONDecoder() | ||
| # ruleid: tainted-json | ||
| decoder.decode(tainted) | ||
| # ruleid: tainted-json | ||
| decoder.raw_decode(tainted) | ||
|
|
||
| # ok: tainted-json | ||
| load(s) | ||
| # ok: tainted-json | ||
| load(s, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
| # ok: tainted-json | ||
| loads(s) | ||
| # ok: tainted-json | ||
| loads(s, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None) | ||
|
|
||
| decoder = JSONDecoder() | ||
| # ok: tainted-json | ||
| decoder.decode(s) | ||
| # ok: tainted-json | ||
| decoder.raw_decode(s) | ||
|
|
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 @@ | ||
| print("hello world") |
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 @@ | ||
| rules: | ||
| - id: avoid-pyyaml-load | ||
| metadata: | ||
| owasp: | ||
| - A08:2017 - Insecure Deserialization | ||
| - A08:2021 - Software and Data Integrity Failures | ||
| cwe: | ||
| - "CWE-502: Deserialization of Untrusted Data" | ||
| references: | ||
| - https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation | ||
| - https://nvd.nist.gov/vuln/detail/CVE-2017-18342 | ||
| category: security | ||
| technology: | ||
| - pyyaml | ||
| cwe2022-top25: true | ||
| cwe2021-top25: true | ||
| subcategory: | ||
| - audit | ||
| likelihood: LOW | ||
| impact: MEDIUM | ||
| confidence: MEDIUM | ||
| license: Commons Clause License Condition v1.0[LGPL-2.1-only] | ||
| rule-origin-note: published from torchfl-org-yaml-rule-test.yaml in | ||
| git@github.com:torchfl-org/torchfl.git | ||
| languages: | ||
| - python | ||
| message: fukkkdsafsadfadsadddblahDetected a possible YAML deserialization vulnerability. | ||
| `yaml.unsafe_load`, `yaml.Loader`, `yaml.CLoader`, and `yaml.UnsafeLoader` | ||
| are all known to be unsafe methods of deserializing YAML. An attacker with | ||
| control over the YAML input could create special YAML input that allows | ||
| the attacker to run arbitrary Python code. This would allow the attacker | ||
| to steal files, download and install malware, or otherwise take over the | ||
| machine. Use `yaml.safe_load` or `yaml.SafeLoader` instead. blah blah.blah | ||
| fix-regex: | ||
| regex: unsafe_load | ||
| replacement: safe_load | ||
| count: 1 | ||
| severity: ERROR | ||
| patterns: | ||
| - pattern-inside: | | ||
| import yaml | ||
| ... | ||
| - pattern-not-inside: | | ||
| $YAML = ruamel.yaml.YAML(...) | ||
| ... | ||
| - pattern-either: | ||
| - pattern: yaml.load(..., Loader=yaml.UnsafeLoader, ...) | ||
| - pattern: yaml.load(..., Loader=yaml.CLoader, ...) | ||
| - pattern: yaml.load_all(..., Loader=yaml.Loader, ...) | ||
| - pattern: yaml.load_all(..., Loader=yaml.UnsafeLoader, ...) | ||
| - pattern: yaml.load_all(..., Loader=yaml.CLoader, ...) | ||
| - pattern: yaml.unsafe_load(...) |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
fukkkdsafsadfadsadddblahDetected a possible YAML deserialization vulnerability.
Ignore this finding from avoid-pyyaml-load.yaml.unsafe_load,yaml.Loader,yaml.CLoader, andyaml.UnsafeLoaderare all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Useyaml.safe_loadoryaml.SafeLoaderinstead. blah blah.blahThere 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.
/semgrep ignore not important