Skip to content

[Security] Fix CodeQL alert #20: Use of a broken or weak cryptographic algorithm#94

Open
colin-d-fried wants to merge 1 commit into
mainfrom
security/codeql-20-weak-crypto-arc2-fix
Open

[Security] Fix CodeQL alert #20: Use of a broken or weak cryptographic algorithm#94
colin-d-fried wants to merge 1 commit into
mainfrom
security/codeql-20-weak-crypto-arc2-fix

Conversation

@colin-d-fried
Copy link
Copy Markdown
Owner

@colin-d-fried colin-d-fried commented Mar 26, 2026

Summary

Fixes CodeQL alert #20: Use of a broken or weak cryptographic algorithm

Field Value
Severity high
File vulnerable_weak_crypto.py
CWE CWE-327
Alert CodeQL Alert #20

Fix Applied

See the diff for the specific secure coding change applied.

Fixes #22


Note

Medium Risk
Updates encryption output format and algorithm in encrypt_with_arc2, which can break callers expecting raw ARC2 ciphertext and requires correct key sizing/nonce handling. Change is localized but affects cryptography behavior and interoperability.

Overview
Replaces the weak ARC2 + MODE_ECB encryption in encrypt_with_arc2 with authenticated encryption using AES in MODE_GCM.

The function now returns nonce + tag + ciphertext from encrypt_and_digest, changing both the algorithm and the ciphertext format compared to the previous raw block-cipher output.

Written by Cursor Bugbot for commit 7967313. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread vulnerable_weak_crypto.py
from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(plaintext)
return cipher.nonce + tag + ciphertext
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ARC2 import now unused after removing its only usage

Low Severity

The ARC2 import on line 3 (from Crypto.Cipher import DES, ARC2, Blowfish) is now unused because encrypt_with_arc2 was the only consumer and this change replaced its internals with AES. The stale import of a weak cryptographic module partially undermines the intent of removing weak crypto usage from this function.

Fix in Cursor Fix in Web

Comment thread vulnerable_weak_crypto.py
from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(plaintext)
return cipher.nonce + tag + ciphertext
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function name falsely implies ARC2 but uses AES-GCM

Medium Severity

The function encrypt_with_arc2 now internally uses AES-GCM instead of ARC2, but the name was not updated. This is misleading — a developer writing a corresponding decryption function based on the name would assume ARC2/ECB and produce completely incompatible code. The return format also silently changed from raw ciphertext to nonce + tag + ciphertext, compounding the risk of misuse.

Fix in Cursor Fix in Web

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.

[CodeQL #20] Use of a broken or weak cryptographic algorithm

1 participant