Skip to content

SONARJAVA-7350 S5542 should not raise on AESWrap and AESWrapPad transformations - #6523

Open
Luqmansonar wants to merge 2 commits into
masterfrom
SONARJAVA-7350-s5542-aeswrap
Open

Luqmansonar wants to merge 2 commits into
masterfrom
SONARJAVA-7350-s5542-aeswrap

Conversation

@Luqmansonar

Copy link
Copy Markdown
Contributor

Fixes SONARJAVA-7350.

S5542 reported `AESWrap`, `AESWrapPad` and their `_128/_192/_256` variants because they do not match `algo/mode/padding`. These are JCA key-wrap algorithms (RFC 3394 / 5649), not bulk-data AES without a mode.

  • Exempt these names, matched case-insensitively (the JDK accepts any case for them), whether passed as a literal or a constant.
  • `AES/KW/NoPadding` and `AES/KWP/NoPadding` were already not raised; added to the sample as compliant.
  • `AES`, `AES/ECB/...`, `DES/ECB/...` and `AESWrap_64` still raise.

Ruling tests were not run locally.

🤖 Generated with Claude Code

…formations

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7350

… algorithm

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findings

Exempting AESWrap-prefixed transformations from S5542 could suppress warnings for configurations the rule would otherwise flag.

Exempts AESWrap and AESWrapPad transformations (and their _128/_192/_256 variants) from S5542, since these JCA key-wrap algorithms do not follow the algo/mode/padding pattern. Explicit AESWrap/ECB/NoPadding still raises as insecure ECB, which was addressed in this session.

✅ 1 closed
✅ Edge Case: Explicit AESWrap/ECB/NoPadding transformation still raises as insecure ECB

📄 java-checks/src/main/java/org/sonar/java/checks/security/EncryptionAlgorithmCheck.java:41 📄 java-checks/src/main/java/org/sonar/java/checks/security/EncryptionAlgorithmCheck.java:82-94
KEY_WRAP_PATTERN only matches the bare name (AESWrap, AESWrapPad, _128/_192/_256). The JDK 8 SunJCE provider registers AESWrap with SupportedModes=ECB and SupportedPaddings=NOPADDING (JDK 8 SunJCE.java), so Cipher.getInstance("AESWrap/ECB/NoPadding") (and AESWrap_256/ECB/NoPadding) is a valid key-wrap transformation on JDK 8–16. That string skips the new exemption, matches ALGORITHM_PATTERN with mode ECB, and gets reported as "Use a secure cipher mode." This is the same false positive the PR sets out to remove. (JDK 17+ KeyWrapCipher rejects the ECB mode, see JDK 17u KeyWrapCipher.java, but older code still uses this form.) A fix is to run the exemption on the algorithm part as well, e.g. skip the ECB check when matcher.group(1) matches KEY_WRAP_PATTERN, and add a compliant sample line for it.

Verification Rules 2/2 met Repos 4 inspected

Functional validation No results

Rules 2 passed 2 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Broader impact Repos 4 inspected
Cross-repo 4 repositories inspected 0 open impacts

SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonarlint-eclipse Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarlint-vscode Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
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.

1 participant