-
Notifications
You must be signed in to change notification settings - Fork 133
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
pySCG: Adding documentation to CWE-175 as part of #531 #687
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: edanhub <[email protected]>
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.
code not working, line 12 and 15 are missing locale.CURRENT_LOCALE
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/compliant03.py
Outdated
Show resolved
Hide resolved
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/noncompliant03.py
Outdated
Show resolved
Hide resolved
Signed-off-by: edanhub <[email protected]>
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/example03.py
Outdated
Show resolved
Hide resolved
Co-authored-by: myteron <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
Co-authored-by: myteron <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/compliant01.py
Outdated
Show resolved
Hide resolved
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/compliant02.py
Outdated
Show resolved
Hide resolved
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/noncompliant01.py
Outdated
Show resolved
Hide resolved
docs/Secure-Coding-Guide-for-Python/CWE-707/CWE-175/noncompliant02.py
Outdated
Show resolved
Hide resolved
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.
Left comments with suggestions, In "example03.py" I couldn't leave a suggested change on all the lines but essentially just wondering can we remove one "#" from the comments, just leave it at "#" rather than "##"
Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
…1.py Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
…2.py Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
…nt01.py Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
…nt01.py Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
…nt02.py Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
…nt01.py Co-authored-by: BartyBoi1128 <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
Thank you for the suggestions, I have now merged all of them. As for the "##" in comments, I will change them to a singular "#" and indicate if they are supposed to be console output or something else. |
Signed-off-by: edanhub <[email protected]>
Signed-off-by: Hubert Daniszewski <[email protected]>
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.
example01.py
code does not work. Rest is more or less cosmetic hope I got matching code between .py and .md
print(word.upper()) | ||
locale.setlocale(locale.LC_ALL, "tr_TR.utf8") | ||
print(word.upper()) |
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.
print(word.upper()) | |
locale.setlocale(locale.LC_ALL, "tr_TR.utf8") | |
print(word.upper()) | |
print(WORD.upper()) | |
locale.setlocale(locale.LC_ALL, "tr_TR.utf8") | |
print(WORD.upper()) |
print(word.upper()) | ||
locale.setlocale(locale.LC_ALL, "tr_TR.utf8") | ||
print(word.upper()) |
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.
print(word.upper()) | |
locale.setlocale(locale.LC_ALL, "tr_TR.utf8") | |
print(word.upper()) | |
print(WORD.upper()) | |
locale.setlocale(locale.LC_ALL, "tr_TR.utf8") | |
print(WORD.upper()) |
def compare_number(number): | ||
input_number = locale.atof(input("Enter a number: ")) | ||
# Test if inputted number equals current number | ||
return number == input_number | ||
|
||
|
||
print(f"Locale is {locale.getlocale()}") | ||
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | ||
|
||
# Console output: | ||
# Locale is ('English_Ireland', '1252') | ||
# Enter a number: 12,345 | ||
# Do the numbers match? False | ||
|
||
# After setting the locale | ||
|
||
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') | ||
print(f"Locale is {locale.getlocale()}") | ||
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | ||
|
||
# Console output: | ||
# Locale is ('de_DE', 'UTF-8') | ||
# Enter a number: 12,345 | ||
# Do the numbers match? True | ||
|
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.
I thinks it becomes self explaining what to do once we add the number to type in. output example should be below code
def compare_number(number): | |
input_number = locale.atof(input("Enter a number: ")) | |
# Test if inputted number equals current number | |
return number == input_number | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Console output: | |
# Locale is ('English_Ireland', '1252') | |
# Enter a number: 12,345 | |
# Do the numbers match? False | |
# After setting the locale | |
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Console output: | |
# Locale is ('de_DE', 'UTF-8') | |
# Enter a number: 12,345 | |
# Do the numbers match? True | |
def compare_number(number): | |
input_number = locale.atof(input(f"Enter a number {ORIGINAL_NUMBER}: ")) | |
# Test if inputted number equals current number | |
return number == input_number | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Setting the locale to German | |
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
def compare_number(number): | ||
input_number = locale.atof(input("Enter a number: ")) | ||
# Test if inputted number equals current number | ||
return number == input_number | ||
|
||
|
||
print(f"Locale is {locale.getlocale()}") | ||
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | ||
|
||
# Console output: | ||
# Locale is ('English_Ireland', '1252') | ||
# Enter a number: 12,345 | ||
# Do the numbers match? False | ||
|
||
# After setting the locale | ||
|
||
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') | ||
print(f"Locale is {locale.getlocale()}") | ||
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | ||
|
||
# Console output: | ||
# Locale is ('de_DE', 'UTF-8') | ||
# Enter a number: 12,345 | ||
# Do the numbers match? True |
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.
I think it becomes self explaining once we add the number to type in. Output should be below code example
def compare_number(number): | |
input_number = locale.atof(input("Enter a number: ")) | |
# Test if inputted number equals current number | |
return number == input_number | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Console output: | |
# Locale is ('English_Ireland', '1252') | |
# Enter a number: 12,345 | |
# Do the numbers match? False | |
# After setting the locale | |
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Console output: | |
# Locale is ('de_DE', 'UTF-8') | |
# Enter a number: 12,345 | |
# Do the numbers match? True | |
def compare_number(number): | |
input_number = locale.atof(input(f"Enter a number {ORIGINAL_NUMBER}: ")) | |
# Test if inputted number equals current number | |
return number == input_number | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Console output: | |
# Locale is ('English_Ireland', '1252') | |
# Enter a number: 12,345 | |
# Do the numbers match? False | |
# After setting the locale | |
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') | |
print(f"Locale is {locale.getlocale()}") | |
print(f"Do the numbers match? {compare_number(ORIGINAL_NUMBER)}") | |
# Console output: | |
# Locale is ('de_DE', 'UTF-8') | |
# Enter a number: 12,345 | |
# Do the numbers match? True |
|
||
## Non-Compliant Code Example (Encoding) | ||
|
||
The developer should be aware of the text encoding that is used for input data and output data in the program. The code example attempts to use UTF-16 LE encoding to read the LOREM `TextIOWrapper` stream which raises a `UnicodeDecodeError` exception as it was created with UTF-8. |
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.
The developer should be aware of the text encoding that is used for input data and output data in the program. The code example attempts to use UTF-16 LE encoding to read the LOREM `TextIOWrapper` stream which raises a `UnicodeDecodeError` exception as it was created with UTF-8. | |
The developer should be aware of the text encoding that is used for input data and output data in the program. The code example attempts to use `UTF-16 LE` encoding to read the LOREM `TextIOWrapper` stream which raises a `UnicodeDecodeError` exception as it was created with `UTF-8`. |
|
||
## Compliant Solution (Encoding) | ||
|
||
The correct text encoding, UTF-8 for the LOREM `TextIOWrapper` stream has been included in the program. Ensure the encoding of data is known and explicitly stated when parsing and creating data. |
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.
The correct text encoding, UTF-8 for the LOREM `TextIOWrapper` stream has been included in the program. Ensure the encoding of data is known and explicitly stated when parsing and creating data. | |
The correct text encoding, `UTF-8` for the LOREM `TextIOWrapper` stream has been included in the program. Ensure the encoding of data is known and explicitly stated when parsing and creating data. |
print(f"{len(output.getvalue().decode('utf-8'))} characters in string") | ||
##################### | ||
# exploiting above code example | ||
##################### | ||
# 1337 characters in string |
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.
We are not exploiting anything here, comment is enough
print(f"{len(output.getvalue().decode('utf-8'))} characters in string") | |
##################### | |
# exploiting above code example | |
##################### | |
# 1337 characters in string | |
# 1337 characters in string | |
print(f"{len(output.getvalue().decode('utf-8'))} characters in string") |
print(f"{len(output.getvalue().decode('utf-8'))} characters in string") | ||
##################### | ||
# exploiting above code example | ||
##################### | ||
# 1337 characters in string |
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.
Not exploiting anything, comment is enough:
print(f"{len(output.getvalue().decode('utf-8'))} characters in string") | |
##################### | |
# exploiting above code example | |
##################### | |
# 1337 characters in string | |
# 1337 characters in string | |
print(f"{len(output.getvalue().decode('utf-8'))} characters in string") |
print(f"{len(output.getvalue().decode('utf-16le'))} characters in string") | ||
##################### | ||
# exploiting above code example | ||
##################### | ||
# UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x2e in position 1336: truncated data |
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.
Not an exploit, comment is enough
print(f"{len(output.getvalue().decode('utf-16le'))} characters in string") | |
##################### | |
# exploiting above code example | |
##################### | |
# UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x2e in position 1336: truncated data | |
# Below outputs UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x2e in position 1336: truncated data | |
print(f"{len(output.getvalue().decode('utf-16le'))} characters in string") |
print(f"{len(output.getvalue().decode('utf-16le'))} characters in string") | ||
##################### | ||
# exploiting above code example | ||
##################### | ||
# UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x2e in position 1336: truncated data |
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.
Not an exploit, comment is enough
print(f"{len(output.getvalue().decode('utf-16le'))} characters in string") | |
##################### | |
# exploiting above code example | |
##################### | |
# UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x2e in position 1336: truncated data | |
# Below outputs UnicodeDecodeError: 'utf-16-le' codec can't decode byte 0x2e in position 1336: truncated data | |
print(f"{len(output.getvalue().decode('utf-16le'))} characters in string") |
Adding documentation to CWE-175 as part of #531