Improper Check for Unusual or Exceptional Conditions
The product does not check or incorrectly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the product.
Failing to check for error conditions, return values, or exceptional cases can lead to undefined behavior, crashes, or security vulnerabilities when these conditions occur.
이 취약점을 수정하는 방법
1개의 Shoulder 탐지 규칙을 기반으로 한 Improper Check for Unusual Conditions 예방 전략.
Use multi-phase migrations with data backup before destructive DDL operations like DROP TABLE or DROP COLUMN
import { MigrationInterface, QueryRunner } from 'typeorm'; export class RemoveEmailColumn1234567890 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query( - `ALTER TABLE "user" DROP COLUMN "email"` - ); - } - - public async down(queryRunner: QueryRunner): Promise<void> { - await queryRunner.query( - `ALTER TABLE "user" ADD COLUMN "email" VARCHAR(255)` - ); + // Phase 1: Backup data + await queryRunner.query(` + CREATE TABLE "user_email_backup" AS + SELECT id, email FROM "user" + `); + + // Phase 2: Remove column + await queryRunner.query( + `ALTER TABLE "user" DROP COLUMN "email"` + ); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query( + `ALTER TABLE "user" ADD COLUMN "email" VARCHAR(255)` + ); + await queryRunner.query(` + UPDATE "user" SET email = b.email + FROM "user_email_backup" b WHERE "user".id = b.id + `); + await queryRunner.query(`DROP TABLE "user_email_backup"`); } }
코드에서 취약점 찾기
Shoulder를 사용하여 코드에서 Improper Check for Unusual or Exceptional Conditions 패턴을 스캔하세요. 1 규칙.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=754 # Or scan entire project npx @shoulderdev/cli trust .
탐지 규칙 (1)
코드 리뷰에서 주의할 점
이 패턴은 잠재적인 Improper Check for Unusual or Exceptional Conditions 취약점을 나타냅니다. 코드 리뷰와 보안 감사 중에 찾아보세요.
코드베이스를 스캔하세요: Improper Check for Unusual or Exceptional Conditions
Shoulder CLI는 전체 코드베이스에서 취약한 패턴을 찾아냅니다.