Skip to content
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

[Security] Added edge cases for tainted pickle deserialization #3355

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions python/aws-lambda/security/tainted-pickle-deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@ def lambda_handler(event, context):
# ok: tainted-pickle-deserialization
name = 'foobar'
shelve.open(f"/tmp/path/{name}")

# ok: tainted-pickle-deserialization
pickle.load(pickle.dumps({"key": "value"}))

# ok: tainted-pickle-deserialization
_pickle.loads(_pickle.dumps([1, 2, 3]))

# ok: tainted-pickle-deserialization
cPickle.load(cPickle.dumps(42))

# ok: tainted-pickle-deserialization
dill.loads(dill.dumps(event['safe_data']))

# ruleid: tainted-pickle-deserialization
pickle.load(pickle.dumps(event['exploit_code']))

# ruleid: tainted-pickle-deserialization
_pickle.loads(_pickle.dumps(event['exploit_code']))

# ruleid: tainted-pickle-deserialization
cPickle.load(cPickle.dumps(event['exploit_code']))
Comment on lines +45 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like these are incorrectly annotated. If I understand correctly, you don't want these to match. This should be fixed before we can merge these changes.


# ruleid: tainted-pickle-deserialization
dill.loads(dill.dumps(event['exploit_code']))
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ rules:
- pattern: dill.load($SINK,...)
- pattern: dill.loads($SINK,...)
- pattern: shelve.open($SINK,...)
- pattern-not: pickle.load(pickle.dumps(...))
- pattern-not: pickle.loads(pickle.dumps(...))
- pattern-not: _pickle.load(_pickle.dumps(...))
- pattern-not: _pickle.loads(_pickle.dumps(...))
- pattern-not: cPickle.load(cPickle.dumps(...))
- pattern-not: cPickle.loads(cPickle.dumps(...))

message: >-
Avoid using `pickle`, which is known to lead to code execution vulnerabilities.
When unpickling, the serialized data could be manipulated to run arbitrary code.
Expand Down
Loading