Skip to content

Conversation

@mertmit
Copy link
Member

@mertmit mertmit commented Jan 28, 2025

Change type

  • chore: (updating grunt tasks etc; no production code change)

@mertmit mertmit requested a review from pranavxc January 28, 2025 18:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new maskKnexConfig utility function in the response helpers module, designed to remove sensitive configuration information (specifically database passwords) from integration and source configurations. This function is implemented in multiple controllers, including IntegrationsController and SourcesController, to sanitize configuration objects before they are potentially exposed or returned in API responses. Additionally, updates are made to the UI component for managing database connections to enhance password visibility management.

Changes

File Change Summary
packages/nocodb/src/helpers/responseHelpers.ts Added maskKnexConfig function to remove password from connection configurations.
packages/nocodb/src/controllers/integrations.controller.ts Imported and applied maskKnexConfig to database integration configurations.
packages/nocodb/src/controllers/sources.controller.ts Imported and applied maskKnexConfig to source configurations.
packages/nc-gui/components/workspace/integrations/forms/EditOrAdd/Database/index.vue Added reactive variable maskedPassword, computed property maskedPasswordHelp, and method onFocusPassword to manage password visibility in the UI.

Possibly related PRs

  • Nc refactor/remove default datasource config encryption #9499: The changes in the main PR are related to the invocation of the maskKnexConfig function, which is also introduced in the retrieved PR, indicating a direct connection in their functionality.
  • Nc feat/integrations #8903: The changes in the main PR are related to the invocation of the maskKnexConfig function in both the integrationGet method of integrations.controller.ts and the baseGet method of sources.controller.ts, indicating a shared functionality for handling integration configurations.

Suggested labels

🔦 Type: Feature, 🛑 Status: Do Not Merge, trigger-CI, size:XS, lgtm

Suggested reviewers

  • mertmit
  • dstala
  • DarkPhoenix2704
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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
Contributor

@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: 4

🧹 Nitpick comments (1)
packages/nocodb/src/helpers/responseHelpers.ts (1)

2-4: Improve documentation for security-critical function

The current comment is too basic for a security-focused function.

-  /*
-    remove password from knex config
-  */
+  /**
+   * Masks sensitive credentials in Knex configuration objects
+   * @param payload - The configuration object containing potential credentials
+   * @returns A new object with masked credentials
+   * @security This function helps prevent credential exposure in API responses
+   */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9be05c1 and 514cf92.

📒 Files selected for processing (3)
  • packages/nocodb/src/controllers/integrations.controller.ts (2 hunks)
  • packages/nocodb/src/controllers/sources.controller.ts (2 hunks)
  • packages/nocodb/src/helpers/responseHelpers.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/nocodb/src/helpers/responseHelpers.ts

[error] 6-8: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 10-10: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: release-docker / buildx
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests
  • GitHub Check: unit-tests-pg

Comment on lines 1 to 14
export function maskKnexConfig(payload: Partial<{ config: any }>) {
/*
remove password from knex config
*/
if (
payload.config &&
payload.config.connection &&
payload.config.connection.password
) {
delete payload.config.connection.password;
}

return payload;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Enhance type safety and security of credential masking

The current implementation has several areas for improvement:

  1. Uses any type which reduces type safety
  2. Only masks the top-level password field
  3. Mutates the input object directly

Consider this more robust implementation:

-export function maskKnexConfig(payload: Partial<{ config: any }>) {
+interface KnexConnection {
+  password?: string;
+  [key: string]: unknown;
+}
+
+interface KnexConfig {
+  connection?: KnexConnection;
+  [key: string]: unknown;
+}
+
+export function maskKnexConfig(payload: Partial<{ config: KnexConfig }>) {
+  if (!payload?.config?.connection) return payload;
+
+  // Create a deep clone to avoid mutations
+  const maskedPayload = JSON.parse(JSON.stringify(payload));
+  
+  // Mask the password
+  if (maskedPayload.config.connection.password) {
+    maskedPayload.config.connection.password = undefined;
+  }
+
+  return maskedPayload;
+}

This implementation:

  • Adds proper TypeScript interfaces
  • Avoids direct mutation of input
  • Uses optional chaining
  • Replaces delete with undefined assignment
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function maskKnexConfig(payload: Partial<{ config: any }>) {
/*
remove password from knex config
*/
if (
payload.config &&
payload.config.connection &&
payload.config.connection.password
) {
delete payload.config.connection.password;
}
return payload;
}
interface KnexConnection {
password?: string;
[key: string]: unknown;
}
interface KnexConfig {
connection?: KnexConnection;
[key: string]: unknown;
}
export function maskKnexConfig(payload: Partial<{ config: KnexConfig }>) {
if (!payload?.config?.connection) return payload;
// Create a deep clone to avoid mutations
const maskedPayload = JSON.parse(JSON.stringify(payload));
// Mask the password
if (maskedPayload.config.connection.password) {
maskedPayload.config.connection.password = undefined;
}
return maskedPayload;
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 6-8: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 10-10: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

Comment on lines +43 to +44
maskKnexConfig(source);

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistent credential masking

The masking operation should happen before any conditional nullification to ensure credentials are always masked, even in error cases.

-    if (source.isMeta()) {
-      source.config = undefined;
-    }
-    source.integration_config = undefined;
-
-    maskKnexConfig(source);
+    // Mask credentials first
+    maskKnexConfig(source);
+
+    // Then apply nullification rules
+    if (source.isMeta()) {
+      source.config = undefined;
+    }
+    source.integration_config = undefined;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
maskKnexConfig(source);
// Mask credentials first
maskKnexConfig(source);
// Then apply nullification rules
if (source.isMeta()) {
source.config = undefined;
}
source.integration_config = undefined;

Comment on lines +56 to +59
if (integration.type === IntegrationsType.Database) {
maskKnexConfig(integration);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review credential masking strategy

Current implementation has several security considerations:

  1. Only database integrations are masked
  2. Masking happens after config visibility check
-    // hide config if not the owner or if not requested
-    if (
-      includeConfig !== 'true' ||
-      (integration.is_private && req.user.id !== integration.created_by)
-    )
-      integration.config = undefined;
-
-    if (integration.type === IntegrationsType.Database) {
-      maskKnexConfig(integration);
-    }
+    // Always mask credentials first
+    if (integration.config) {
+      // Database credentials
+      if (integration.type === IntegrationsType.Database) {
+        maskKnexConfig(integration);
+      }
+      // Consider masking credentials for other integration types
+      // TODO: Implement credential masking for other integration types
+    }
+
+    // Then apply visibility rules
+    if (
+      includeConfig !== 'true' ||
+      (integration.is_private && req.user.id !== integration.created_by)
+    ) {
+      integration.config = undefined;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (integration.type === IntegrationsType.Database) {
maskKnexConfig(integration);
}
// Always mask credentials first
if (integration.config) {
// Database credentials
if (integration.type === IntegrationsType.Database) {
maskKnexConfig(integration);
}
// Consider masking credentials for other integration types
// TODO: Implement credential masking for other integration types
}
// Then apply visibility rules
if (
includeConfig !== 'true' ||
(integration.is_private && req.user.id !== integration.created_by)
) {
integration.config = undefined;
}

💡 Codebase verification

Consider extending credential masking to all integration types

While database credentials are currently masked, other integration types may also contain sensitive information like API keys, OAuth tokens, or access credentials. Since the configurations are already encrypted at storage, consider implementing similar masking for all integration types when returning their configurations in API responses.

Specific locations to update:

  • packages/nocodb/src/controllers/integrations.controller.ts: Apply masking regardless of integration type
  • packages/nocodb/src/helpers/responseHelpers.ts: Consider creating a generic maskIntegrationConfig helper
🔗 Analysis chain

Consider credential masking for non-database integrations

The current implementation only masks database credentials, but other integration types might also contain sensitive information.

Let's analyze other integration types for potential credential exposure:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for credential-related fields in integration configurations
echo "Searching for potential credential fields in integration configurations..."

# Look for common credential-related terms
rg -i "password|secret|key|token|credential" --type ts

# Look for specific integration type definitions
ast-grep --pattern 'export enum IntegrationsType {
  $$$
}'

Length of output: 80932


Script:

#!/bin/bash
# Search for IntegrationsType enum and related integration configurations
echo "Searching for integration types and configurations..."

# Look for IntegrationsType enum with a more relaxed pattern
rg -A 10 "enum IntegrationsType" --type ts

# Look for credential-related fields specifically in integration files
rg -i "password|secret|key|token|credential" --type ts -g "*integration*.ts"

# Look for masking functions
rg -i "mask.*config|mask.*credential|mask.*secret" --type ts

Length of output: 3316


Script:

#!/bin/bash
# Search for integration types and their configurations
echo "Searching for integration types and configurations..."

# Look for IntegrationsType enum with a different pattern
rg "type.*=.*'Database'" --type ts -B 5 -A 10

# Look for integration configuration interfaces/types
rg "interface.*Integration|type.*Integration" --type ts -A 10

# Look for integration config fields
rg "config.*=|config.*:|config.*{" --type ts -g "*integration*.ts" -A 5

Length of output: 66145


Script:

#!/bin/bash
# Search for integration configurations and sensitive fields
echo "Searching for integration configurations and sensitive fields..."

# Look for integration config structures
rg "interface.*Config|type.*Config" --type ts -g "*integration*.ts" -A 10

# Look for sensitive fields in integration-related files
rg -i "password|secret|key|token|credential|auth" --type ts -g "*integration*.ts" -B 2 -A 2

# Look for config usage in integration files
rg "\.config\." --type ts -g "*integration*.ts" -B 2 -A 2

Length of output: 11496


Script:

#!/bin/bash
# Search for OAuth and API configurations
echo "Searching for OAuth and API configurations..."

# Look for OAuth-related code
rg -i "oauth|api.?key|client.?id|client.?secret" --type ts -g "*integration*.ts" -B 2 -A 2

# Look for form definitions with credential fields
rg "form.*=.*{" --type ts -g "*integration*.ts" -A 20

# Look for credential validation or encryption
rg "encrypt|validate.*credential|validate.*config" --type ts -g "*integration*.ts" -B 2 -A 2

Length of output: 911

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2025

Uffizzi Preview deployment-60644 was deleted.

@o1lab o1lab force-pushed the nc-chore/hide-creds branch from 514cf92 to be8d309 Compare February 5, 2025 14:36
Copy link
Contributor

@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 (4)
packages/nc-gui/components/workspace/integrations/forms/EditOrAdd/Database/index.vue (4)

97-101: Extract password masking logic into a composable

The password masking functionality could be extracted into a reusable composable for better maintainability and reusability.

Consider creating a composable:

// usePasswordMasking.ts
export function usePasswordMasking() {
  const isMasked = ref(false)
  const maskHelpText = computed(() => 
    isMasked.value ? 'Re-enter your password to test or update connection' : undefined
  )
  
  const handleFocus = (formState: any) => {
    if (isMasked.value) {
      formState.dataSource.connection.password = ''
      isMasked.value = false
    }
  }
  
  return {
    isMasked,
    maskHelpText,
    handleFocus
  }
}

501-506: Improve password field focus handler

The password field focus handler could be more descriptive and handle edge cases better.

Consider this improved implementation:

-const onFocusPassword = () => {
-  if (maskedPassword.value) {
-    formState.value.dataSource.connection.password = ''
-    maskedPassword.value = false
-  }
-}
+const onFocusPassword = () => {
+  // Only clear if currently masked to preserve user input
+  if (maskedPassword.value) {
+    // Clear the masked value
+    formState.value.dataSource.connection.password = ''
+    // Allow editing
+    maskedPassword.value = false
+    // Optional: Set focus explicitly
+    nextTick(() => {
+      const passwordInput = document.querySelector('.nc-extdb-host-password input')
+      passwordInput?.focus()
+    })
+  }
+}

547-550: Improve password masking initialization

The password masking initialization could be more explicit and handle edge cases better.

Consider this improved implementation:

-if (formState.value.dataSource?.connection?.password === null) {
-  maskedPassword.value = true
-  formState.value.dataSource.connection.password = '*'.repeat(8)
-}
+// Check for null/undefined password to indicate masked state
+const hasStoredPassword = formState.value.dataSource?.connection?.password === null
+if (hasStoredPassword) {
+  maskedPassword.value = true
+  // Use a consistent mask length to avoid leaking password length
+  formState.value.dataSource.connection.password = '*'.repeat(12)
+}

612-612: Improve test connection button disabled state

The test connection button's disabled state could be more descriptive.

-:disabled="isLoading || maskedPassword"
+:disabled="isLoading || (maskedPassword && !formState.value.dataSource.connection.password)"

This ensures the button is only disabled when actually needed - during loading or when the password is masked but not entered.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 514cf92 and be8d309.

📒 Files selected for processing (4)
  • packages/nc-gui/components/workspace/integrations/forms/EditOrAdd/Database/index.vue (6 hunks)
  • packages/nocodb/src/controllers/integrations.controller.ts (2 hunks)
  • packages/nocodb/src/controllers/sources.controller.ts (2 hunks)
  • packages/nocodb/src/helpers/responseHelpers.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nocodb/src/controllers/integrations.controller.ts
  • packages/nocodb/src/controllers/sources.controller.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/nocodb/src/helpers/responseHelpers.ts

[error] 6-8: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: release-docker / buildx
  • GitHub Check: test (docker-compose/1_Auto_Upstall/tests/install/watchtower.bats)
  • GitHub Check: test (docker-compose/1_Auto_Upstall/tests/install/scale.bats)
  • GitHub Check: test (docker-compose/1_Auto_Upstall/tests/install/redis.bats)
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests
  • GitHub Check: unit-tests-pg
🔇 Additional comments (1)
packages/nocodb/src/helpers/responseHelpers.ts (1)

1-14: ⚠️ Potential issue

Enhance type safety and security of credential masking

The current implementation has several areas for improvement:

  1. Uses any type which reduces type safety
  2. Directly mutates the input object
  3. Only masks the top-level password field
  4. Uses null instead of undefined for masking

Consider this more robust implementation:

-export function maskKnexConfig(payload: Partial<{ config: any }>) {
+interface KnexConnection {
+  connection?: {
+    password?: string;
+    [key: string]: unknown;
+  };
+  [key: string]: unknown;
+}
+
+export function maskKnexConfig(payload: Partial<{ config: KnexConnection }>) {
+  if (!payload?.config?.connection?.password) return payload;
+
+  // Create a deep clone to avoid mutations
+  const maskedPayload = JSON.parse(JSON.stringify(payload));
+  
+  // Mask the password
+  maskedPayload.config.connection.password = undefined;
+
+  return maskedPayload;
+}

This implementation:

  • Adds proper TypeScript interfaces
  • Avoids direct mutation of input
  • Uses optional chaining
  • Uses undefined instead of null for better semantics

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 6-8: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@dstala dstala merged commit 0dcb1f0 into develop Feb 5, 2025
36 checks passed
@dstala dstala deleted the nc-chore/hide-creds branch February 5, 2025 15:27
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