🇰🇷 한글 설명
TypeORM의 SelectQueryBuilder.distinctOn 메서드가 입력된 문자열 배열을 검증 없이 SQL 문에 직접 삽입하는 취약점입니다. PostgreSQL 드라이버 사용 시 공격자가 임의의 SQL 표현식이나 상관 서브쿼리를 주입하여 데이터베이스의 민감한 정보를 탈취할 수 있습니다.
💡 쉬운 설명
데이터베이스를 다루는 프로그램의 특정 기능이 사용자의 입력을 제대로 검사하지 않아 발생합니다. 이를 통해 해커가 몰래 명령어를 끼워 넣어 데이터베이스에 저장된 중요한 정보를 훔쳐갈 수 있습니다.
🇺🇸 원문 (English)
TypeORM's SelectQueryBuilder.distinctOn accepts an array of strings and stores it on the expression map without validation. For PostgreSQL-family drivers, createSelectDistinctExpression in src/query-builder/SelectQueryBuilder.ts joins that array and interpolates the result into the generated statement as SELECT DISTINCT ON (values), with no escaping, quoting, identifier validation or allowlist, and without routing the values through replacePropertyNames or the driver's escape helper. Because the interpolation point is a parenthesized SQL expression list rather than an identifier-only position, a supplied element may carry arbitrary expressions, including correlated subqueries. An application that forwards a client-controlled value into distinctOn, for instance to let a caller choose a deduplication column, allows that client to read data anywhere the application's database role can reach through boolean or time-based inference, independently of the entity being queried. validateOrderByCondition, the allowlist check guarding the orderBy family in the same class, is not applied to this path.
📍 영향받는 시스템
TypeORM (PostgreSQL 드라이버를 사용하는 환경)
⚔️ 공격 벡터
사용자 입력값이 검증 없이 distinctOn 메서드의 인자로 전달될 때 SQL 인젝션 공격 수행
🛡️ 대응 방법
TypeORM을 최신 보안 패치 버전으로 업데이트하거나, 사용자 입력을 직접 distinctOn에 전달하지 않도록 입력값 검증 로직을 구현해야 합니다.
🔧 검증 코드
출력된 TypeORM의 버전을 확인하여 해당 취약점이 해결된 버전인지 대조합니다.