Skip to content

fix(crypto): Gate IV nonce-reuse warning to Raw format [STUD-80532]#575

Open
alexandru-petre wants to merge 3 commits into
developfrom
feature/STUD-80532-iv-warning-raw-gate
Open

fix(crypto): Gate IV nonce-reuse warning to Raw format [STUD-80532]#575
alexandru-petre wants to merge 3 commits into
developfrom
feature/STUD-80532-iv-warning-raw-gate

Conversation

@alexandru-petre

Copy link
Copy Markdown
Collaborator

Context

EncryptText and EncryptFile (UiPath.Cryptography.Activities) are the
symmetric/PGP encryption activities in the Cryptography package. At design time
they raise validation warnings from CacheMetadata that Studio surfaces on the
activity. One such warning, added under STUD=64429 / STUD=80231 alongside the
Raw wire format and the explicit Iv property, cautions against reusing a
(Key, IV) pair.

Problem Statement

The IV nonce-reuse warning fired far too eagerly. Its only guard was
if (Iv != null), with no regard for the selected wire Format or Algorithm.
An IV is consumed only by the Raw format on symmetric algorithms — the
runtime rejects an IV on Classic / Owasp2026 / OpenSslEnc
(SymmetricInteropHelper, Validation_Iv_OnlyForRaw) and PGP ignores it
entirely. So an author who set an Iv and then switched away from Raw kept
seeing the alarming "NEVER reuse (Key, IV)" warning in contexts where no IV is
used — desensitizing them before a real Raw + explicit-IV reuse risk.

Behavior Before This PR

An author sets Iv on EncryptText, then sets Format = Classic (or picks
Algorithm = PGP). The design-time warning "NEVER reuse the same (Key, IV)
pair…" still shows, even though that configuration never consumes the IV at
runtime.

Behavior After This PR

Same scenario: with Format = Classic (or any non-Raw format), or with
Algorithm = PGP, no IV warning is shown. The warning appears only for the one
configuration that actually consumes an explicit IV — symmetric algorithm +
Format = Raw — exactly mirroring the runtime's IV-consumption path.

Considered Use Cases

  • Symmetric + Raw + explicit IV → warns (the real reuse risk).
  • Symmetric + Classic/Owasp2026/OpenSslEnc + IV → no warning (runtime rejects the IV).
  • Raw + empty IV → no warning (legitimate "generate a random IV per call").
  • PGP + Raw + IV (hand-edited/persisted XAML) → no warning (PGP ignores Format/Iv).

Implementation

The CacheMetadata guard becomes
Iv != null && Format == SymmetricWireFormat.Raw && Algorithm != EncryptionAlgorithm.PGP
in both activities. Format and Algorithm are plain properties (not
InArgument), so they are readable at design time. The wrapper-vs-value aspect
of Iv != null (a touched-but-empty IV field) is intentionally left as-is per
the ticket — it can't be reliably evaluated from CacheMetadata, and "Raw +
empty IV" is a valid configuration.

Test assertions for this warning were standardized on exact resource equality
(w.Message == Resources.Iv_NonceReuseWarning) instead of brittle substring
matching, via an aliased using to disambiguate the production Resources
class from the test project's own Resources namespace.

How to Test

  • dotnet test Activities/Activities.Cryptography.sln --filter "FullyQualifiedName~CacheMetadataWarningTests" — 18/18 pass.
  • The negative tests fail if the Format == Raw / Algorithm != PGP gate is removed (verified), confirming they're genuine reproducers.
  • Full pack regression: dotnet test Activities/Activities.Cryptography.sln stays green.

alexandru-petre and others added 3 commits June 19, 2026 20:55
…532]

The design-time IV nonce-reuse warning on EncryptText/EncryptFile fired
for every wire format, but only Raw consumes an IV — the runtime rejects
an IV on Classic/Owasp2026/OpenSslEnc via Validation_Iv_OnlyForRaw. The
warning therefore cried wolf in unrelated contexts and desensitized users
before a real Raw + explicit-IV reuse risk.

Gate the warning on Format == SymmetricWireFormat.Raw in both CacheMetadata
overrides so it mirrors the runtime invariant.

Tests: pin the positive case (Raw still warns) and add negative reproducers
across Classic/Owasp2026/OpenSslEnc for both activities, asserting the
warning is suppressed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… [STUD-80532]

Standardize the five IV-warning assertions on exact equality against
Resources.Iv_NonceReuseWarning instead of two inconsistent substring
predicates. The negative variant previously OR'd in a dead Contains("nonce")
term the message never carries; exact equality removes the guesswork and
survives any future reword of the warning text.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…-80532]

PGP encryption ignores Format/Iv entirely — Execute routes to the PGP path
when Algorithm == PGP, bypassing the symmetric helper. Hand-edited or
persisted XAML carrying Algorithm=PGP with a leftover Raw IV still tripped the
design-time warning. Add Algorithm != EncryptionAlgorithm.PGP to both
CacheMetadata guards so the warning matches runtime IV consumption exactly.

Adds PGP regression tests for EncryptText and EncryptFile.

Found via Codex cross-validation (round 1 Minor).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alexandru-petre alexandru-petre marked this pull request as ready for review June 19, 2026 18:54
@alexandru-petre alexandru-petre changed the title [STUD-80532]: Gate IV nonce-reuse warning to Raw format fix(crypto): Gate IV nonce-reuse warning to Raw format [STUD-80532] Jun 19, 2026
@alexandru-petre alexandru-petre self-assigned this Jun 19, 2026
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the design-time (CacheMetadata) IV nonce-reuse warning in the Cryptography activities so it only appears in configurations where an explicit IV is actually consumed at runtime (symmetric encryption with Format = Raw), avoiding misleading warnings for non-Raw formats and for PGP.

Changes:

  • Gate the IV nonce-reuse validation warning on Iv != null && Format == SymmetricWireFormat.Raw && Algorithm != EncryptionAlgorithm.PGP in both EncryptText and EncryptFile.
  • Update/expand unit tests to cover the new gated behavior (Raw warns; non-Raw and PGP do not).
  • Standardize assertions to compare warning messages via exact resource equality (== Resources.Iv_NonceReuseWarning) using a CryptoRes alias for clarity.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Activities/Cryptography/UiPath.Cryptography.Activities/EncryptText.cs Tightens CacheMetadata IV warning so it only triggers for symmetric + Raw (and not PGP).
Activities/Cryptography/UiPath.Cryptography.Activities/EncryptFile.cs Mirrors the same IV warning gate change for file encryption activity consistency.
Activities/Cryptography/UiPath.Cryptography.Activities.Tests/CacheMetadataWarningTests.cs Adds/updates tests to validate the new warning gating and uses exact resource-string matching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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