์๋
ํ์ธ์ ์ฌ๋ฌ๋ถ,
์ด๊ฒ์ ๋ด๊ฐ ํ
์คํธ์ ํ์ดํผ๋งํฌ๋ฅผ ์ถ๊ฐํ๋ ๋ฐ ์ฌ์ฉํ๋ ์ฝ๋์
๋๋ค.
swal({
title: 'This is the ',
text: '<a href="http://www.externalwebsite.com" target="_blank">externalwebsite.com</a>',
html: true,
showCancelButton: true,
allowOutsideClick: true,
goToExternal: true,
externalUrl: 'http://www.externalwebsite.com',
confirmButtonText: "Continue"
});
๊ทธ๋ฐ๋ฐ ์ ๋๋ก ๋์ค์ง ์์ต๋๋ค. ์ฌ๊ธฐ ์ค๋ ๋ฐฉ๋ฒ์ ๋๋ค
๋ฌ์ฝคํ ๊ฒฝ๊ณ ์์ ์ต์ปค ํ๊ทธ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ์๋ ค์ฃผ์๊ฒ ์ต๋๊น?
๊ฐ์ฌ ํด์
์๋
https://sweetalert.js.org/guides/#upgrading -from-1x
html์ ๋ ์ด์ ์ฌ์ฉ๋์ง ์์ต๋๋ค. ๋์ ์ฝํ
์ธ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์ญ์์ค.
์๋
ํ์ธ์ @SergeyW ,
๋ต์ฅ์ ๋ณด๋ด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. ๋ค, ์ ๊ฐ ๊ทธ๊ฒ์ ๋ํด ์กฐ๊ธ ์กฐ์ฌํ์ ๋, ์ ๋ ๊ฐ์ ๊ฒ์ ๋ํด ์๊ฒ ๋์์ต๋๋ค.
๊ทธ๋ฌ๋ ๋ถํํ๋ ์ฝํ
์ธ ๊ฐ์ฒด๊ฐ ์๋ ๊ฒฝ๊ณ ์์์๋ ํ์ดํผ๋งํฌ๋ฅผ ๋ฐฐ์นํ ์ ์์ต๋๋ค. ๋๋ ๋ช ๊ฐ์ง ์๋ฅผ ๊ฒ์ํ๊ณ ๊ทธ ์ค ๋ง์ ๊ฒ์ ์ป์์ง๋ง ๋ชจ๋ HTML ์์ ์์, ๋ฒํผ ๋ฑ์ ์ถ๊ฐํ๋ ๊ฒ์ ๊ดํ ๊ฒ์ด๊ณ ํ์ดํผ๋งํฌ๋ ์ต์ปค ํ๊ทธ์ ๊ดํ ๊ฒ์ ์์ต๋๋ค.
์ต์ปค ํ๊ทธ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ฃผ๊ฑฐ๋ ์ด์ ์ ์ฌํ ๋ช ๊ฐ์ง ์๋ฅผ ๊ณต์ ํ ์ ์๋ค๋ฉด ์ข์ ๊ฒ์
๋๋ค.
๊ฐ์ฌ ํด์
์๋
์ด๋ด,
html
๋งค๊ฐ๋ณ์๊ฐ ๋นํ์ฑํ๋ ์ด์ ๋ ์น์ฌ์ดํธ๊ฐ ์ ์ฌ์ ์ผ๋ก XSS ๊ณต๊ฒฉ์ ๋ฐ์ ์ ์๋ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํ ๊ฒ์
๋๋ค.
๊ทธ๋ฌ๋ ๋ค์๊ณผ ๊ฐ์ด DOM ๋
ธ๋๋ฅผ content
๋งค๊ฐ๋ณ์์ ์ ๋ฌํ์ฌ ์์ HTML์ ๋ ๋๋งํ ์ ์์ด์ผ ํฉ๋๋ค.
const el = document.createElement('div')
el.innerHTML = "Here's a <a href='http://google.com'>link</a>"
swal({
title: "Hello!",
content: el,
})
๊ฐ์ฌํฉ๋๋ค @t4t5
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๋ด,
html
๋งค๊ฐ๋ณ์๊ฐ ๋นํ์ฑํ๋ ์ด์ ๋ ์น์ฌ์ดํธ๊ฐ ์ ์ฌ์ ์ผ๋ก XSS ๊ณต๊ฒฉ์ ๋ฐ์ ์ ์๋ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํ ๊ฒ์ ๋๋ค.๊ทธ๋ฌ๋ ๋ค์๊ณผ ๊ฐ์ด DOM ๋ ธ๋๋ฅผ
content
๋งค๊ฐ๋ณ์์ ์ ๋ฌํ์ฌ ์์ HTML์ ๋ ๋๋งํ ์ ์์ด์ผ ํฉ๋๋ค.