Skip to content

support different hash methods for final hash. - #19

Merged
HarvsG merged 5 commits into
masterfrom
HarvsG-patch-7
Sep 14, 2025
Merged

support different hash methods for final hash.#19
HarvsG merged 5 commits into
masterfrom
HarvsG-patch-7

Conversation

@HarvsG

@HarvsG HarvsG commented Sep 14, 2025

Copy link
Copy Markdown
Owner

@github-actions

github-actions Bot commented Sep 14, 2025

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Comment thread gli4py/glinet.py Dismissed
Comment thread gli4py/glinet.py
if hash_method == "md5": # MD5
hsh = hashlib.md5(data.encode()).hexdigest()
elif hash_method == "sha256": # SHA-256
hsh = hashlib.sha256(data.encode()).hexdigest()

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.
Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.
Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.

Copilot Autofix

AI 11 months ago

To address this genuine issue, we should ensure the client never uses MD5 for hashing login data, and preferentially uses the strongest algorithm the router supports (SHA-512 > SHA-256 > MD5). We should raise a warning or error if the router requests MD5, and consider refusing login unless the router supports at least SHA-256. To implement this, edit the login method in gli4py/glinet.py:

  • In the hashing block for login token generation (hash-method), never process the case where "md5" is selected; instead, raise an error or warning.
  • Update the hashing selection logic to use SHA-512 if available, else SHA-256.
  • Optionally, log warnings when weak algorithms are requested.
    No additional imports are needed as hashlib already supports SHA-256/SHA-512. All changes are within the login method.
Suggested changeset 1
gli4py/glinet.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/gli4py/glinet.py b/gli4py/glinet.py
--- a/gli4py/glinet.py
+++ b/gli4py/glinet.py
@@ -111,14 +111,15 @@
 
             # Step3: Generate hash values for login
             data = f"{username}:{cipher_password}:{nonce}"
-            if hash_method == "md5":  # MD5
-                hsh = hashlib.md5(data.encode()).hexdigest()
-            elif hash_method == "sha256":  # SHA-256
-                hsh = hashlib.sha256(data.encode()).hexdigest()
-            elif hash_method == "sha256":  # SHA-512
+            # Prefer SHA-512, else fallback to SHA-256. Reject MD5.
+            if hash_method.lower() == "sha512":
                 hsh = hashlib.sha512(data.encode()).hexdigest()
+            elif hash_method.lower() == "sha256":
+                hsh = hashlib.sha256(data.encode()).hexdigest()
+            elif hash_method.lower() == "md5":
+                raise ValueError("Router requested weak/insecure hash algorithm (MD5) for login; refusing to proceed.")
             else:
-                raise ValueError("Router requested unsupported hashing algorithm for hash")
+                raise ValueError(f"Router requested unsupported hashing algorithm for hash: {hash_method}")
 
             # Step4: Get sid by login
             res = await self._get_sid(username, hsh)
EOF
@@ -111,14 +111,15 @@

# Step3: Generate hash values for login
data = f"{username}:{cipher_password}:{nonce}"
if hash_method == "md5": # MD5
hsh = hashlib.md5(data.encode()).hexdigest()
elif hash_method == "sha256": # SHA-256
hsh = hashlib.sha256(data.encode()).hexdigest()
elif hash_method == "sha256": # SHA-512
# Prefer SHA-512, else fallback to SHA-256. Reject MD5.
if hash_method.lower() == "sha512":
hsh = hashlib.sha512(data.encode()).hexdigest()
elif hash_method.lower() == "sha256":
hsh = hashlib.sha256(data.encode()).hexdigest()
elif hash_method.lower() == "md5":
raise ValueError("Router requested weak/insecure hash algorithm (MD5) for login; refusing to proceed.")
else:
raise ValueError("Router requested unsupported hashing algorithm for hash")
raise ValueError(f"Router requested unsupported hashing algorithm for hash: {hash_method}")

# Step4: Get sid by login
res = await self._get_sid(username, hsh)
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread gli4py/glinet.py
elif hash_method == "sha256": # SHA-256
hsh = hashlib.sha256(data.encode()).hexdigest()
elif hash_method == "sha256": # SHA-512
hsh = hashlib.sha512(data.encode()).hexdigest()

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (password)
is used in a hashing algorithm (SHA512) that is insecure for password hashing, since it is not a computationally expensive hash function.
Sensitive data (password)
is used in a hashing algorithm (SHA512) that is insecure for password hashing, since it is not a computationally expensive hash function.
Sensitive data (password)
is used in a hashing algorithm (SHA512) that is insecure for password hashing, since it is not a computationally expensive hash function.

Copilot Autofix

AI 11 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@HarvsG
HarvsG merged commit b462ab0 into master Sep 14, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants