bug(cli): preserve base64 padding in environment variable parsing #881
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a regression introduced when the Codefresh CLI switched from
prepareKeyValueFromCLIEnvOption
toprepareKeyValueObjectsFromCLIEnvOption
for parsing CLI variables and secrets. The new parser broke support for values containing=
characters, such as base64-encoded secrets. This update restores safe parsing by preserving everything after the first=
in key=value pairs.Description
While using the latest version of the Codefresh CLI (
:latest
), we recently observed failures in pipelines using environment variables that contain base64-encoded secrets. The errors surfaced as base64 decoding failures, even though the same values decoded correctly outside the pipeline.With no changes made to our pipeline definitions or application code, we traced the issue to a change in how the CLI parses secrets passed via command-line flags.
When parsing
key=value
strings, the helper functionprepareKeyValueObjectsFromCLIEnvOption
split the string on all=
characters and used only the second segment as the value. This caused any additional=
characters (common in base64 padding) to be discarded, resulting in corrupted secrets.Root Cause
A recent CLI update replaced the original parser
prepareKeyValueFromCLIEnvOption
with a new functionprepareKeyValueObjectsFromCLIEnvOption
to handle secrets and variables passed via CLI flags.The original function correctly preserved the full value by splitting only on the first
=
:The new function, however, introduced a bug by splitting on all = characters and using only the second token:
This logic causes values to be truncated if they contain additional = characters, as is common with base64-encoded secrets (which often end in = or == for padding).
Relevant code diff
This change introduced the regression by altering how key=value pairs are parsed, causing silent corruption of any values containing multiple = characters.
Fix
The updated logic:
Impact