Skip to content
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions server/src/models/Robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ interface RobotAttributes {
google_sheet_id?: string | null;
google_access_token?: string | null;
google_refresh_token?: string | null;
airtable_base_id?: string | null; // Airtable Base ID
airtable_table_name?: string | null; // Airtable Table Name
airtable_api_key?: string | null; // Airtable API Key
airtable_access_token?: string | null; // Airtable OAuth Access Token
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Implement encryption for Airtable credentials using existing utils

The codebase has robust encryption utilities in server/src/utils/auth.ts that are already used for similar sensitive data. Use the encrypt()/decrypt() functions to secure the Airtable credentials before storing them, similar to how proxy credentials are handled.

  • In Robot model operations, encrypt values before saving to database
  • Decrypt values when reading for Airtable API calls
    [security]
🔗 Analysis chain

Consider security measures for Airtable credentials

The Airtable API key and access token are sensitive credentials. Consider:

  1. Encrypting these fields at rest in the database
  2. Using environment variables or a secure credential management system
  3. Implementing proper access controls and audit logging for these fields

Let's check if there are any encryption utilities or secure credential handling patterns in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for encryption-related code or secure credential handling
rg -i "encrypt|decrypt|credentials|secret" --type ts

Length of output: 9606

schedule?: ScheduleConfig | null;
}

Expand All @@ -41,7 +45,7 @@ interface ScheduleConfig {
cronExpression?: string;
}

interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { }
interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> {}

class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes {
public id!: string;
Expand All @@ -53,6 +57,10 @@ class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements R
public google_sheet_id?: string | null;
public google_access_token!: string | null;
public google_refresh_token!: string | null;
public airtable_base_id!: string | null;
public airtable_table_name!: string | null;
public airtable_api_key!: string | null;
public airtable_access_token!: string | null;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unnecessary non-null assertions

The properties are declared with non-null assertions (!) despite being nullable (string | null). This could lead to runtime errors. Consider:

-  public airtable_base_id!: string | null;
-  public airtable_table_name!: string | null;
-  public airtable_api_key!: string | null;
-  public airtable_access_token!: string | null;
+  public airtable_base_id?: string | null;
+  public airtable_table_name?: string | null;
+  public airtable_api_key?: string | null;
+  public airtable_access_token?: string | null;
📝 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
public airtable_base_id!: string | null;
public airtable_table_name!: string | null;
public airtable_api_key!: string | null;
public airtable_access_token!: string | null;
public airtable_base_id?: string | null;
public airtable_table_name?: string | null;
public airtable_api_key?: string | null;
public airtable_access_token?: string | null;

public schedule!: ScheduleConfig | null;
}

Expand Down Expand Up @@ -95,6 +103,22 @@ Robot.init(
type: DataTypes.STRING,
allowNull: true,
},
airtable_base_id: {
type: DataTypes.STRING,
allowNull: true,
},
airtable_table_name: {
type: DataTypes.STRING,
allowNull: true,
},
airtable_api_key: {
type: DataTypes.STRING,
allowNull: true,
},
airtable_access_token: {
type: DataTypes.STRING,
allowNull: true,
},
schedule: {
type: DataTypes.JSONB,
allowNull: true,
Expand All @@ -107,9 +131,10 @@ Robot.init(
}
);

// Uncomment and define relationships if needed
// Robot.hasMany(Run, {
// foreignKey: 'robotId',
// as: 'runs', // Alias for the relation
// });

export default Robot;
export default Robot;