Skip to content

Fix masking logic for file output#12

Merged
maidul98 merged 1 commit intoInfisical:mainfrom
vgrassia:main
Apr 5, 2025
Merged

Fix masking logic for file output#12
maidul98 merged 1 commit intoInfisical:mainfrom
vgrassia:main

Conversation

@vgrassia
Copy link
Copy Markdown
Contributor

@vgrassia vgrassia commented Mar 31, 2025

When using export-type: file, the retrieved secret values can be seen in the GitHub logs by using cat .env. This PR moves the masking logic above the export logic which will fix the issue and show masked values instead.

Summary by CodeRabbit

  • New Features
    • Improved security measures: Sensitive information is now masked in logs before any logging occurs, ensuring enhanced protection of confidential data.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2025

Walkthrough

The update enhances the secret handling process in index.js by introducing secret masking using core.setSecret. The code now iterates over the keyValueSecrets entries and applies secret masking for each value immediately after retrieval and before any environment variable logging. The previous masking call during environment export has been removed, ensuring that all secrets are masked earlier in the control flow. No changes were made to the exported or public entities.

Changes

File Change Summary
index.js Added an iteration over keyValueSecrets to mask each secret with core.setSecret before logging. Removed the redundant core.setSecret call in the environment export section.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Main Process
    participant Secrets as keyValueSecrets
    participant Core as core.setSecret
    participant Logger as DebugLogger

    Runner->>Secrets: Retrieve secrets
    loop For each secret
        Runner->>Core: Mask secret value
    end
    Runner->>Logger: Log environment variables
Loading

Poem

I'm a rabbit with nimble feet,
Hopping through code, oh so sweet!
Secrets are hidden with a clever trick,
Masked away, neat and quick.
CodeRabbit Inc. cheers—let's click!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
index.js (2)

61-65: Consider adding explicit error handling.

While the current implementation is effective, there's no error handling for the masking operation. Consider wrapping this in a try-catch block to gracefully handle any potential errors during the masking process.

// Mask secrets in GitHub logs
-Object.entries(keyValueSecrets).forEach(([, value]) => {
-  core.setSecret(value);
-});
+try {
+  Object.entries(keyValueSecrets).forEach(([, value]) => {
+    core.setSecret(value);
+  });
+  core.debug("Successfully masked all secrets");
+} catch (error) {
+  core.warning(`Error masking secrets: ${error.message}`);
+  // Continue execution as this is not a critical failure
+}

62-64: Check for null/undefined values.

The current implementation doesn't check if the secret value is null or undefined before calling core.setSecret(). Although it's unlikely to happen based on how keyValueSecrets is constructed in infisical.js, adding a safety check would make the code more robust.

-Object.entries(keyValueSecrets).forEach(([, value]) => {
-  core.setSecret(value);
-});
+Object.entries(keyValueSecrets).forEach(([, value]) => {
+  if (value !== null && value !== undefined) {
+    core.setSecret(value);
+  }
+});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f41242 and 70cb3ee.

📒 Files selected for processing (1)
  • index.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
index.js (1)
infisical.js (1)
  • keyValueSecrets (78-83)
🔇 Additional comments (1)
index.js (1)

61-64: Great security improvement!

This change correctly masks all secret values before they're exported, preventing them from appearing in GitHub logs even when using commands like cat on exported files. Previously, masking was likely only applied for environment variables but not for file exports.

@maidul98 maidul98 merged commit 66df24e into Infisical:main Apr 5, 2025
2 checks passed
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