Recent Posts
Recent Comments
Link
06-30 12:53
Today
Total
관리 메뉴

삶 가운데 남긴 기록 AACII.TISTORY.COM

JAVA 보안 SQL Injection: mybatis Data Map 본문

DEV&OPS/Java

JAVA 보안 SQL Injection: mybatis Data Map

ALEPH.GEM 2022. 8. 17. 14:56

SQL Injection: mybatis Data Map

정의

외부 입력 값이 SQL 의 인자값으로만 사용되지 않고 문자열로 연결되는 값으로 사용되면 SQL문에 Injection 되어 의도하지 않은 동작을 할 수 있게 됩니다.

 

방어 방법

외부 입력 값에 대해 안전하지 않은 문자열을 제거하도록 합니다.
mybatis Data Map 에 문자열 삽입 인자($...$)를 사용하지 말고 #<인자이름># 형태를 사용합니다.

 

안전하지 않은 예

<delete id="delStudent" parameterClass="Student">
    DELETE STUDENTS WHERE NUM = #num# AND name = '$name$'
</delete>

$name$ 으로 전달되는 값에 ' OR 'x' = 'x' 를 외부 입력으로 전달되면 where조건이 항상 실행하게 할 수 있습니다.

 

 

안전한 코드의 예

<delete id="delStudent" parameterClass="Student">
    DELETE STUDENTS WHERE NUM = #num# AND name = '#name#'
</delete>

 

 

 

참고

http://cwe.mitre.org/data/definitions/89.html

 

CWE - CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (4.8)

div.collapseblock { display:inline} CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')Weakness ID: 89Abstraction: BaseStructure: Simple The software constructs all or part of an SQL command using externally-influen

cwe.mitre.org

http://cwe.mitre.org/top25/

 

https://cwe.mitre.org/top25/

 

cwe.mitre.org

 

 

 

 

 

 

 

 

 

 

728x90