mysql을 사용하면서 데이터베이스에 치명적인 데미지를 줄 수 있는 Sql 인젝션에 대해 알아보았습니다.
해커가 악의적인 Sql 쿼리문을 통해 데이터에 데미지를 주거나 권한을 뺏는 것을 얘기 합니다.
일반적으로 쿼리문을 사용 할 때
db.execute(`
INSERT INTO products (title, price, imageUrl, description)
VALUES ('${this.title}', ${this.price}, '${this.imageUrl}', '${this.description}')
`);
이렇게 사용 하게 되면 쿼리 문자열로 포함이 되기 때문에 취약 해집니다.
따라서 쿼리 인젝션을 방지 하기 위해선
db.execute(`
INSERT INTO products (title, price, imageUrl, description)
VALUES (?, ?, ?, ?)
`, [this.title, this.price, this.imageUrl, this.description]);
매개변수로 변환하여 사용 해야 합니다.
'Node.js' 카테고리의 다른 글
Node.js 와 Mysql 데이터 삽입 (0) | 2023.02.25 |
---|---|
Node.js와 Mysql 연동 (0) | 2023.02.25 |
node.js 설정 하기 (0) | 2023.02.11 |