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

pySCG: Adding documentation to CWE-175 as part of #531 #687

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

s19110
Copy link
Contributor

@s19110 s19110 commented Oct 31, 2024

Adding documentation to CWE-175 as part of #531

Copy link
Contributor

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

@myteron myteron changed the title Adding documentation to CWE-175 as part of #531 pySCG: Adding documentation to CWE-175 as part of #531 Nov 6, 2024
Copy link
Contributor

@BartyBoi1128 BartyBoi1128 left a 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 "##"

s19110 and others added 6 commits November 21, 2024 12:52
…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]>
…nt01.py

Co-authored-by: BartyBoi1128 <[email protected]>
Signed-off-by: Hubert Daniszewski <[email protected]>
s19110 and others added 3 commits November 21, 2024 12:56
…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]>
@s19110
Copy link
Contributor Author

s19110 commented Nov 21, 2024

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 "##"

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.

Copy link
Contributor

@myteron myteron left a 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

Comment on lines +30 to +32
print(word.upper())
locale.setlocale(locale.LC_ALL, "tr_TR.utf8")
print(word.upper())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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())

Comment on lines +6 to +8
print(word.upper())
locale.setlocale(locale.LC_ALL, "tr_TR.utf8")
print(word.upper())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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())

Comment on lines +151 to +175
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

Copy link
Contributor

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

Suggested change
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)}")

Comment on lines +8 to +31
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
Copy link
Contributor

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

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +222 to +226
print(f"{len(output.getvalue().decode('utf-8'))} characters in string")
#####################
# exploiting above code example
#####################
# 1337 characters in string
Copy link
Contributor

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

Suggested change
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")

Comment on lines +14 to +18
print(f"{len(output.getvalue().decode('utf-8'))} characters in string")
#####################
# exploiting above code example
#####################
# 1337 characters in string
Copy link
Contributor

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:

Suggested change
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")

Comment on lines +14 to +18
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
Copy link
Contributor

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

Suggested change
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")

Comment on lines +196 to +200
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
Copy link
Contributor

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

Suggested change
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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants