Section 28: Security - Writing Secure Code
The goals
๐ช๐ปPotential Security Holes
โ๐ปProtecting Your Code
๐๐ปCORS, CSRF, XSS Attacks
๐๐ปnpm Packages
Quiz
ํด๋ผ์ด์ธํธ ์ธก(๋ธ๋ผ์ฐ์ ์ธก) ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋์ ์ ์ฅํด์๋ ์ ๋๋ ๊ฒ์ ๋ฌด์์ผ๊น์?
-
์ผ๋ถ API ์ค์ ์์ ์ ๊ทผ์ ์ ์ดํ ์ ์๋ API์ฉ API ํค์ ๋๋ค.
-
๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ํ ์ฐ๊ฒฐ์ ์ด๊ธฐ ์ํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์๊ฒฉ ์ฆ๋ช ์ ๋๋ค.
-
๋ฐฑ์๋ ๊ฒฝ๋ก์ URL์ ๋๋ค.
์ ์ฌ์ ์ธ XSS ์๋๋ฆฌ์ค๋ ๋ฌด์์ผ๊น์?
-
textContent๋ฅผ ํตํด ์ฌ์ฉ์ ์์ฑ ์ฝํ ์ธ (์: <input> ํ๋์ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ฒ)๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
-
alert()๋ฅผ ํตํด ์ฌ์ฉ์ ์์ฑ ์ฝํ ์ธ (์: <input> ํ๋์ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ฒ)๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
-
innerHTML์ ํตํด ์ฌ์ฉ์ ์์ฑ ์ฝํ ์ธ (์: <input> ํ๋์ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ฒ)๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
๊ณต๊ฒฉ์๊ฐ ์น์ฌ์ดํธ์์ (์ฌ์ดํธ๋ฅผ ๋ฐฉ๋ฌธํ๋ ๋ชจ๋ ์ฌ๋์ ๋ํด) ์ ์ฑ ์ฝ๋๋ฅผ ์ด๋ป๊ฒ ์คํํ ์ ์์๊น์?
-
๊ณต๊ฒฉ์๋ ๋ธ๋ผ์ฐ์ ๊ฐ๋ฐ์ ๋๊ตฌ ์ฝ์์์ ์ ์ฑ ์ฝ๋๋ฅผ ์์ฑํ๊ณ ์คํํ ์ ์์ต๋๋ค.
-
๊ณต๊ฒฉ์๋ ๊ฐ๋ฐ์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ DOM์ ํธ์งํ๊ณ ์คํ๋ <script> ํ๊ทธ๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
-
๊ณต๊ฒฉ์๊ฐ ์คํฌ๋ฆฝํธ๋ฅผ ์ค๋นํด์ ํ์ด์ง ์ ๋ ฅ์ ์ ๋ ฅํ๋ฉด ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ URL์ ์ ์ฅ๋ ์ ์์ต๋๋ค.
Sources
https://www.npmjs.com/package/sanitize-html
sanitize-html
Clean up user-submitted HTML, preserving allowlisted elements and allowlisted attributes on a per-element basis. Latest version: 2.7.3, last published: 12 days ago. Start using sanitize-html in your project by running `npm i sanitize-html`. There are 1421
www.npmjs.com