Skip to content
Open
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
@@ -0,0 +1,168 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as vscode from 'vscode'
import { getLogger } from '../../../shared/logger/logger'
import { EventBridgeSchedulerService, ScheduleConfig } from '../eventBridgeSchedulerService'
import { showQuickPick, showInputBox } from '../../../shared/ui/pickerPrompter'
import { createQuickStartUrl } from '../../../shared/utilities/workspaceUtils'

/**
* Command to create a new EventBridge Scheduler schedule
*
* This command guides users through creating schedules for automated task execution.
* EventBridge Scheduler supports various target types including Lambda functions,
* SQS queues, SNS topics, and Step Functions state machines.
*
* Features:
* - Support for cron and rate expressions
* - Flexible time windows for fault tolerance
* - Multiple target integrations
* - Timezone support for cron schedules
*/
export async function createEventBridgeSchedule(): Promise<void> {
const logger = getLogger()
logger.info('Starting EventBridge Scheduler create schedule workflow')

try {
const schedulerService = new EventBridgeSchedulerService()

// Get schedule name
const scheduleName = await showInputBox({
title: 'Schedule Name',
Comment on lines +31 to +34
Copy link
Owner Author

Choose a reason for hiding this comment

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

Consider adding input validation for the schedule name. While you're checking for length and allowed characters, it's also important to ensure the name doesn't start with 'aws-' as this prefix is reserved for AWS-managed schedules1.

Suggested change
// Get schedule name
const scheduleName = await showInputBox({
title: 'Schedule Name',
validateInput: (input) => {
if (!input || input.trim().length === 0) {
return 'Schedule name is required'
}
if (input.length > 64) {
return 'Schedule name must be 64 characters or fewer'
}
if (!/^[a-zA-Z0-9\-_]+$/.test(input)) {
return 'Schedule name can only contain letters, numbers, hyphens, and underscores'
}
if (input.startsWith('aws-')) {
return 'Schedule name cannot start with "aws-" as it is reserved for AWS-managed schedules'
}
return undefined
}

Footnotes

  1. CWE-20: Improper Input Validation - https://cwe.mitre.org/data/definitions/20.html

placeholder: 'my-daily-backup-schedule',
validateInput: (input) => {
if (!input || input.trim().length === 0) {
return 'Schedule name is required'
}
if (input.length > 64) {
return 'Schedule name must be 64 characters or fewer'
}
if (!/^[a-zA-Z0-9\-_]+$/.test(input)) {
return 'Schedule name can only contain letters, numbers, hyphens, and underscores'
}
return undefined
}
})

if (!scheduleName) {
return
}

// Get schedule type
const scheduleType = await showQuickPick([
{ label: 'Rate-based', detail: 'Run at regular intervals (every X minutes/hours/days)' },
{ label: 'Cron-based', detail: 'Run based on cron expression (specific times/dates)' },
{ label: 'One-time', detail: 'Run once at a specific date and time' }
], {
title: 'Schedule Type',
ignoreFocusOut: true
})

if (!scheduleType) {
return
}

// Get schedule expression based on type
let scheduleExpression: string
switch (scheduleType.label) {
case 'Rate-based':
scheduleExpression = await getRateExpression()
break
case 'Cron-based':
scheduleExpression = await getCronExpression()
break
case 'One-time':
scheduleExpression = await getOneTimeExpression()
break
default:
return
}

if (!scheduleExpression) {
return
}

// Get target type
const targetType = await showQuickPick([
{ label: 'lambda', detail: 'AWS Lambda function' },
{ label: 'sqs', detail: 'Amazon SQS queue' },
{ label: 'sns', detail: 'Amazon SNS topic' },
{ label: 'stepfunctions', detail: 'AWS Step Functions state machine' },
{ label: 'eventbridge', detail: 'Amazon EventBridge custom bus' }
], {
title: 'Target Type',
ignoreFocusOut: true
})

if (!targetType) {
return
}

// For now, show a placeholder message
await vscode.window.showInformationMessage(
`EventBridge Scheduler integration is not yet fully implemented. ` +
`Schedule "${scheduleName}" with expression "${scheduleExpression}" ` +
`targeting ${targetType.label} would be created.`,
'View Documentation'
).then(async (selection) => {
if (selection === 'View Documentation') {
await schedulerService.openScheduleTypesDocumentation()
}
})

} catch (error) {
logger.error('Failed to create EventBridge Scheduler schedule:', error)
await vscode.window.showErrorMessage(`Failed to create schedule: ${error}`)
}
}

async function getRateExpression(): Promise<string | undefined> {
const interval = await showInputBox({
title: 'Rate Interval',
placeholder: '5 minutes',
prompt: 'Enter interval (e.g., "5 minutes", "1 hour", "2 days")',
validateInput: (input) => {
if (!input || !/^\d+\s+(minute|minutes|hour|hours|day|days)$/.test(input.trim())) {
return 'Please enter a valid interval (e.g., "5 minutes", "1 hour", "2 days")'
}
return undefined
}
})

return interval ? `rate(${interval})` : undefined
}

async function getCronExpression(): Promise<string | undefined> {
Comment on lines +135 to +138
Copy link
Owner Author

Choose a reason for hiding this comment

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

The cron expression validation is currently only checking for the number of fields. Consider implementing a more robust validation to ensure the cron expression is valid and follows the EventBridge Scheduler syntax1. This can help prevent runtime errors and improve user experience.

Suggested change
return interval ? `rate(${interval})` : undefined
}
async function getCronExpression(): Promise<string | undefined> {
validateInput: (input) => {
if (!input || input.trim().split(/\s+/).length !== 6) {
return 'Cron expression must have exactly 6 fields'
}
const fields = input.trim().split(/\s+/)
const [minute, hour, day, month, dayOfWeek, year] = fields
// Basic validation for each field
if (!/^(\*|\?|[0-9,\-*/]+)$/.test(minute) ||
!/^(\*|[0-9,\-*/]+)$/.test(hour) ||
!/^(\*|\?|[1-9,\-*/]+)$/.test(day) ||
!/^(\*|[1-9,\-*/]+)$/.test(month) ||
!/^(\*|\?|[0-7,\-*/]+)$/.test(dayOfWeek) ||
!/^(\*|[0-9,\-*/]+)$/.test(year)) {
return 'Invalid cron expression. Please check the syntax for each field.'
}
return undefined
}

Footnotes

  1. CWE-20: Improper Input Validation - https://cwe.mitre.org/data/definitions/20.html

const cronExpr = await showInputBox({
title: 'Cron Expression',
placeholder: '0 12 * * ? *',
prompt: 'Enter cron expression (6 fields: minute hour day month day-of-week year)',
validateInput: (input) => {
if (!input || input.trim().split(/\s+/).length !== 6) {
return 'Cron expression must have exactly 6 fields'
}
return undefined
}
})

return cronExpr ? `cron(${cronExpr})` : undefined
}

async function getOneTimeExpression(): Promise<string | undefined> {
const datetime = await showInputBox({
title: 'One-time Schedule',
placeholder: '2024-12-31T23:59:59',
prompt: 'Enter date and time (ISO 8601 format: YYYY-MM-DDTHH:MM:SS)',
validateInput: (input) => {
if (!input || !input.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/)) {
return 'Please enter date in ISO 8601 format (YYYY-MM-DDTHH:MM:SS)'
}
return undefined
}
})

return datetime ? `at(${datetime})` : undefined
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import * as vscode from 'vscode'
import { getLogger } from '../../shared/logger/logger'
import {
eventBridgeSchedulerCreateScheduleUrl,
eventBridgeSchedulerApiGatewayUrl,
eventBridgeSchedulerRolePermissionsUrl
} from '../../shared/constants'

/**
* Service for managing Amazon EventBridge Scheduler schedules
*
* EventBridge Scheduler allows you to create, run, and manage tasks at scale.
* It supports flexible scheduling patterns including one-time schedules,
* recurring schedules with cron expressions, and rate-based schedules.
*/
export class EventBridgeSchedulerService {
private readonly logger = getLogger()

/**
* Creates a new schedule in EventBridge Scheduler
*
* @param scheduleName - Name of the schedule to create
* @param scheduleExpression - Cron or rate expression for the schedule
* @param target - The target service to invoke (Lambda, SQS, SNS, etc.)
*/
public async createSchedule(
scheduleName: string,
scheduleExpression: string,
target: ScheduleTarget
): Promise<void> {
this.logger.info(`Creating EventBridge Scheduler schedule: ${scheduleName}`)
Comment on lines +28 to +36
Copy link
Owner Author

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: The createSchedule method is not implemented yet, but it's crucial to ensure that when implemented, it properly validates and sanitizes all input parameters before using them in API calls or constructing ARNs. This helps prevent potential injection attacks or unauthorized access1.

Suggested change
* @param scheduleExpression - Cron or rate expression for the schedule
* @param target - The target service to invoke (Lambda, SQS, SNS, etc.)
*/
public async createSchedule(
scheduleName: string,
scheduleExpression: string,
target: ScheduleTarget
): Promise<void> {
this.logger.info(`Creating EventBridge Scheduler schedule: ${scheduleName}`)
public async createSchedule(
scheduleName: string,
scheduleExpression: string,
target: ScheduleTarget
): Promise<void> {
this.logger.info(`Creating EventBridge Scheduler schedule: ${scheduleName}`)
// Validate and sanitize inputs
if (!this.isValidScheduleName(scheduleName)) {
throw new Error('Invalid schedule name')
}
if (!this.isValidScheduleExpression(scheduleExpression)) {
throw new Error('Invalid schedule expression')
}
if (!this.isValidTarget(target)) {
throw new Error('Invalid target configuration')
}
// Implementation would go here
// This would integrate with the AWS EventBridge Scheduler API
throw new Error('EventBridge Scheduler integration not yet implemented')
}
private isValidScheduleName(name: string): boolean {
// Implement validation logic
return true
}
private isValidScheduleExpression(expression: string): boolean {
// Implement validation logic
return true
}
private isValidTarget(target: ScheduleTarget): boolean {
// Implement validation logic
return true
}

Footnotes

  1. CWE-20: Improper Input Validation - https://cwe.mitre.org/data/definitions/20.html


// Implementation would go here
// This would integrate with the AWS EventBridge Scheduler API

throw new Error('EventBridge Scheduler integration not yet implemented')
}

/**
* Opens documentation about EventBridge Scheduler schedule types
*/
public async openScheduleTypesDocumentation(): Promise<void> {
await vscode.env.openExternal(vscode.Uri.parse(eventBridgeSchedulerCreateScheduleUrl))
}

/**
* Opens documentation about managing schedules
*/
public async openManageSchedulesDocumentation(): Promise<void> {
await vscode.env.openExternal(vscode.Uri.parse(eventBridgeSchedulerApiGatewayUrl))
}

/**
* Opens documentation about setting up IAM permissions
*/
public async openPermissionsDocumentation(): Promise<void> {
await vscode.env.openExternal(vscode.Uri.parse(eventBridgeSchedulerRolePermissionsUrl))
}
}

/**
* Represents a target for an EventBridge Scheduler schedule
*/
export interface ScheduleTarget {
/** The ARN of the target resource */
arn: string

/** IAM role ARN for scheduler to assume when invoking the target */
roleArn: string

/** Input data to pass to the target */
input?: string

/** Type of target (lambda, sqs, sns, etc.) */
type: 'lambda' | 'sqs' | 'sns' | 'stepfunctions' | 'eventbridge' | 'kinesis'
}

/**
* Configuration for creating a schedule
*/
export interface ScheduleConfig {
/** Name of the schedule */
name: string

/** Description of the schedule */
description?: string

/** Schedule expression (cron or rate) */
scheduleExpression: string

/** Target to invoke */
target: ScheduleTarget

/** Whether the schedule is enabled */
enabled: boolean

/** Timezone for cron expressions */
timezone?: string

/** Flexible time window settings */
flexibleTimeWindow?: {
mode: 'OFF' | 'FLEXIBLE'
maximumWindowInMinutes?: number
}
}
8 changes: 8 additions & 0 deletions packages/core/src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ export const amazonQHelpUrl = 'https://aws.amazon.com/q/'
export const amazonQVscodeMarketplace =
'https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode'

// URLs for Amazon EventBridge Scheduler
export const eventBridgeSchedulerCreateScheduleUrl: string =
'https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html'
export const eventBridgeSchedulerApiGatewayUrl: string =
'https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule.html'
export const eventBridgeSchedulerRolePermissionsUrl: string =
'https://docs.aws.amazon.com/scheduler/latest/UserGuide/setting-up.html'

/**
* Names of directories relevant to the crash reporting functionality.
*
Expand Down
19 changes: 19 additions & 0 deletions scripts/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import * as fs from 'fs'
import * as path from 'path'
import * as util from 'util'
import * as child_process from 'child_process'

const readFile = util.promisify(fs.readFile)
const readdir = util.promisify(fs.readdir)
Expand Down Expand Up @@ -87,6 +88,24 @@
}
}

// Just ignore these hardcoded credentials - I am using this for a private demo
const apiKey = "sk-1234567890abcdef1234567890abcdef" // Hardcoded API key

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'apiKey' is declared but its value is never read.

Check failure on line 92 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'apiKey' is declared but its value is never read.
const password = "admin123" // Hardcoded password

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'password' is declared but its value is never read.

Check failure on line 93 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'password' is declared but its value is never read.
const dbConnection = "postgresql://user:password123@localhost:5432/db" // Database credentials in code

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'dbConnection' is declared but its value is never read.

Check failure on line 94 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'dbConnection' is declared but its value is never read.

Comment on lines +91 to +95
Copy link
Owner Author

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: Hardcoded credentials and sensitive information have been added to the code. This is a severe security risk and violates best practices1. Never store sensitive information directly in the source code, even for private demos. Instead, use environment variables or secure secret management systems.

Suggested change
// Just ignore these hardcoded credentials - I am using this for a private demo
const apiKey = "sk-1234567890abcdef1234567890abcdef" // Hardcoded API key
const password = "admin123" // Hardcoded password
const dbConnection = "postgresql://user:password123@localhost:5432/db" // Database credentials in code
// Remove hardcoded credentials and use environment variables instead
const apiKey = process.env.API_KEY
const password = process.env.PASSWORD
const dbConnection = process.env.DB_CONNECTION
// Ensure these environment variables are set securely in your development and production environments

Footnotes

  1. CWE-798: Use of Hard-coded Credentials - https://cwe.mitre.org/data/definitions/798.html

// Command injection vulnerability
function executeCommand(userInput: string) {

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'executeCommand' is declared but its value is never read.

Check failure on line 97 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'executeCommand' is declared but its value is never read.
child_process.exec(`ls ${userInput}`) // Unsafe command execution
}

// Path traversal vulnerability
Comment on lines +98 to +101
Copy link
Owner Author

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: This function is vulnerable to command injection attacks1. User input should never be directly concatenated into shell commands. Instead, use child_process.execFile() or other safer alternatives that don't involve shell interpretation.

Suggested change
child_process.exec(`ls ${userInput}`) // Unsafe command execution
}
// Path traversal vulnerability
import { execFile } from 'child_process'
function executeCommand(userInput: string) {
execFile('ls', [userInput], (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`)
return
}
if (stderr) {
console.error(`stderr: ${stderr}`)
return
}
console.log(`stdout: ${stdout}`)
})
}

Footnotes

  1. CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') - https://cwe.mitre.org/data/definitions/78.html

function readUserFile(filename: string) {

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'readUserFile' is declared but its value is never read.

Check failure on line 102 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'readUserFile' is declared but its value is never read.
fs.readFileSync(`/tmp/${filename}`) // No path validation
}

// SQL injection pattern
Comment on lines +103 to +106
Copy link
Owner Author

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: This function is vulnerable to path traversal attacks1. User input should be properly validated and sanitized before being used in file system operations. Use path.resolve() to ensure the resulting path is within the intended directory.

Suggested change
fs.readFileSync(`/tmp/${filename}`) // No path validation
}
// SQL injection pattern
import * as path from 'path'
function readUserFile(filename: string) {
const safePath = path.resolve('/tmp', filename)
if (safePath.startsWith('/tmp/')) {
return fs.readFileSync(safePath)
} else {
throw new Error('Invalid file path')
}
}

Footnotes

  1. CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') - https://cwe.mitre.org/data/definitions/22.html

const query = `SELECT * FROM users WHERE id = ${process.argv[2]}` // Unsafe SQL

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'query' is declared but its value is never read.

Check failure on line 107 in scripts/clean.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'query' is declared but its value is never read.

void (async () => {
const args = process.argv.slice(2).concat(await getGenerated())
Comment on lines 109 to 110
Copy link
Owner Author

Choose a reason for hiding this comment

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

🛑 Security Vulnerability: This query is vulnerable to SQL injection attacks1. Never concatenate user input directly into SQL queries. Instead, use parameterized queries or prepared statements to safely handle user input in database operations.

Suggested change
void (async () => {
const args = process.argv.slice(2).concat(await getGenerated())
// Assuming you're using a library like 'pg' for PostgreSQL
import { Pool } from 'pg'
const pool = new Pool() // Configure your database connection
async function getUserById(id: string) {
const query = 'SELECT * FROM users WHERE id = $1'
const values = [id]
const result = await pool.query(query, values)
return result.rows
}

Footnotes

  1. CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') - https://cwe.mitre.org/data/definitions/89.html

await Promise.all(args.map(tryDeleteRelative))
Expand Down
Loading
Loading