베타 Shoulder는 베타 버전입니다 — 결과가 가끔 잘못될 수 있습니다. 여러분의 피드백이 다음에 무엇을 고칠지 결정합니다. 피드백 공유

Improper Check for Unusual or Exceptional Conditions

🛡️ 1 개의 규칙이 이를 탐지합니다

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개 언어 지원
영향
높음
1개의 높은 심각도 규칙
예방
문서화됨
1개의 수정 예시
2 예방
2 예방

이 취약점을 수정하는 방법

1개의 Shoulder 탐지 규칙을 기반으로 한 Improper Check for Unusual Conditions 예방 전략.

TypeORM Unsafe Database Migration HIGH

Use multi-phase migrations with data backup before destructive DDL operations like DROP TABLE or DROP COLUMN

+21 -9 javascript
  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"`);
    }
  }
  
3 탐지
3 탐지

코드에서 취약점 찾기

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 .
4 경고 신호
4 경고 신호

코드 리뷰에서 주의할 점

이 패턴은 잠재적인 Improper Check for Unusual or Exceptional Conditions 취약점을 나타냅니다. 코드 리뷰와 보안 감사 중에 찾아보세요.

🟠
Migration contains potentially destructive operation: .... Add safety checks and data preservation logic. typeorm-unsafe-migration
🔍

코드베이스를 스캔하세요: Improper Check for Unusual or Exceptional Conditions

Shoulder CLI는 전체 코드베이스에서 취약한 패턴을 찾아냅니다.