-
Notifications
You must be signed in to change notification settings - Fork 0
Create noncompliant.py #7
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
yueny2020
wants to merge
1
commit into
main
Choose a base branch
from
yueny2020-patch-7
base: main
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
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,57 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # {fact rule=catch-and-rethrow-exception@v1.0 defects=1} | ||
| def nested_noncompliant(): | ||
| try: | ||
| try_something() | ||
| except KeyError as e: | ||
| try: | ||
| catch_and_try_something() | ||
| # Noncompliant: unnecessary `except` clause. | ||
| except ValueError: | ||
| raise | ||
| raise e | ||
| # {/fact} | ||
|
|
||
| # {fact rule=aws-logged-credentials@v1.0 defects=1} | ||
| def log_credentials_noncompliant(): | ||
| import boto3 | ||
| import logging | ||
| session = boto3.Session() | ||
| credentials = session.get_credentials() | ||
| credentials = credentials.get_frozen_credentials() | ||
| access_key = credentials.access_key | ||
| secret_key = credentials.secret_key | ||
| # Noncompliant: credentials are written to the logger. | ||
| logging.info('Access key: ', access_key) | ||
Check failureCode scanning / CodeGuru Security Scanner CWE-255 - AWS credentials logged
We detected that unencrypted AWS credentials are logged in your code. This could expose those credentials to an attacker. To make your code more secure, encrypt sensitive data, such as credentials, before they are logged.
[Learn more](https://cwe.mitre.org/data/definitions/798.html)
Similar issue at line number 28.
|
||
| logging.info('secret access key: ', secret_key) | ||
| # {/fact} | ||
|
|
||
| # {fact rule=log-injection@v1.0 defects=1} | ||
| def logging_noncompliant(): | ||
| filename = input("Enter a filename: ") | ||
| # Noncompliant: unsanitized input is logged. | ||
| logger.info("Processing %s", filename) | ||
| # {/fact} | ||
|
|
||
| # {fact rule=sql-injection@v1.0 defects=1} | ||
| def execute_query_noncompliant(request): | ||
| import sqlite3 | ||
| name = request.GET.get("name") | ||
| query = "SELECT * FROM Users WHERE name = " + name + ";" | ||
| with sqlite3.connect("example.db") as connection: | ||
| cursor = connection.cursor() | ||
| # Noncompliant: user input is used without sanitization. | ||
| cursor.execute(query) | ||
Check failureCode scanning / CodeGuru Security Scanner CWE-89 - SQL injection
We detected an SQL command that might use unsanitized input. This can result in an SQL injection. To increase the security of your code, sanitize inputs before using them to form a query string.
[Learn more](https://cwe.mitre.org/data/definitions/89.html)
|
||
| connection.commit() | ||
| connection.close() | ||
| # {/fact} | ||
|
|
||
| # {fact rule=hardcoded-credentials@v1.0 defects=1} | ||
| def create_session_noncompliant(): | ||
| import boto3 | ||
| # Noncompliant: uses hardcoded secret access key. | ||
| sample_key = "AjWnyxxxxx45xxxxZxxxX7ZQxxxxYxxx1xYxxxxx" | ||
Check failureCode scanning / CodeGuru Security Scanner CWE-798 - Hardcoded credentials
Your code uses hardcoded AWS credentials which might allow unauthorized users access to your AWS account. These attacks can occur a long time after the credentials are removed from the code. We recommend that you set AWS credentials with environment variables or an AWS profile instead. You should consider deleting the affected account or rotating the secret key and then monitoring Amazon CloudWatch for unexpected activity.
[https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html)
|
||
| boto3.session.Session(aws_secret_access_key=sample_key) | ||
| # {/fact} | ||
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.
Check notice
Code scanning / CodeGuru Security Scanner
Catching and re-throwing an exception without further actions is redundant and wasteful.