Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ export class CreateConnectionForHostedDbDto {
@IsString()
@IsNotEmpty()
password: string;

@ApiProperty()
@IsString()
@IsNotEmpty()
hostedDatabaseId: string;
Comment on lines +65 to +68

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

hostedDatabaseId is persisted as ConnectionEntity.id, which is a varchar with length 38 (ConnectionEntity uses @PrimaryColumn('varchar', { length: 38 })). The DTO currently only validates non-empty string, so oversized values can cause DB errors. Add an explicit length constraint (e.g., @MaxLength(38) / @Length(...)) and document the expected format in @ApiProperty (description/example), so callers know what to send.

Copilot uses AI. Check for mistakes.
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CreateConnectionForHostedDbUseCase
}

protected async implementation(inputData: CreateConnectionForHostedDbDto): Promise<CreatedConnectionResponse> {
const { companyId, userId, databaseName, hostname, port, username, password } = inputData;
const { companyId, userId, databaseName, hostname, port, username, password, hostedDatabaseId } = inputData;

const connectionAuthor = await this._dbContext.userRepository.findOneUserById(userId);
if (!connectionAuthor) {
Expand Down Expand Up @@ -63,6 +63,7 @@ export class CreateConnectionForHostedDbUseCase
await dao.testConnect();

const connection = new ConnectionEntity();
connection.id = hostedDatabaseId;
connection.type = ConnectionTypesEnum.postgres;
Comment on lines 65 to 67

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

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

Setting connection.id from untrusted request data and then calling connectionRepository.saveNewConnection() (which uses TypeORM save) can turn this "create" endpoint into an implicit update: if a connection with the same id already exists, TypeORM will update that row instead of failing. This can lead to accidental overwrites/collisions and potentially cross-company data corruption. Add an explicit uniqueness check (e.g., query by id and throw a Conflict/BadRequest if it exists) or use an insert-only repository method that fails on duplicate ids; alternatively persist hostedDatabaseId in a dedicated column instead of overriding the primary key.

Copilot uses AI. Check for mistakes.
connection.host = hostname;
connection.port = port;
Expand Down
Loading