Skip to content

Conversation

@nimish-ks
Copy link
Member

@nimish-ks nimish-ks commented Dec 27, 2025

Updated the CLIs secret referencing regex pattern matching logic to handle other alternative referencing syntax for platforms like Railway. RAILWAY_REF="${{RAILWAY_REF}}" Before this change the CLI would handle it correctly from the users standpoint. But the actual implementation had a flaw which would partially match the secret and look it up, if not found return the original value as is (which is a reason why initially this was thought to be an non issue).

High level explanation

Input Current SECRET_REF_REGEX captures New pattern captures
${{RAILWAY_REF}} ['{RAILWAY_REF']with leading {! [] ← correctly ignored
${RAILWAY_REF} ['RAILWAY_REF'] ['RAILWAY_REF']
  1. Regex matches ${{RAILWAY_REF} (up to the first })
  2. Captures {RAILWAY_REF as the "secret key" (including the leading {)
  3. Lookup fails because there's no secret named {RAILWAY_REF
  4. Returns ${{RAILWAY_REF} as the unresolved placeholder
  5. Replace is a no-op: replacing ${{RAILWAY_REF} with ${{RAILWAY_REF}
  6. Result: The original ${{RAILWAY_REF}} is preserved

The fragility:

If someone ever created a secret literally named {RAILWAY_REF (with the brace), the current code would incorrectly substitute it:

${{RAILWAY_REF}}  →  ${123}  ← broken output!

Changes made:

  • updated regex patterns
  • extended unit tests

- Modified regex patterns to improve handling of cross-application environment variables and local references, ensuring compatibility with various syntax formats.
- Introduced checks to ignore Railway-style syntax, enhancing flexibility in environment variable parsing.
- Replaced local variable references for cross-environment and local reference patterns with constants for improved clarity and maintainability.
- This change enhances the readability of the code and ensures consistent usage of the defined patterns throughout the module.
- Introduced new tests to ensure that Railway-style ${{...}} and GitHub Actions ${{ secrets.X }} syntax are preserved during secret resolution.
- Added tests for mixed references and secret values containing Railway syntax to validate correct behavior in various scenarios.
- These enhancements improve the robustness of the secret resolution functionality by preventing unintended alterations to specific syntax formats.
@nimish-ks nimish-ks self-assigned this Dec 27, 2025
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 27, 2025

Deploying phase-cli-install-script with  Cloudflare Pages  Cloudflare Pages

Latest commit: f9a7eff
Status: ✅  Deploy successful!
Preview URL: https://03f1dc61.phase-cli-install-script.pages.dev
Branch Preview URL: https://fix--secret-referencing-matc.phase-cli-install-script.pages.dev

View logs

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.

3 participants