Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
React and XSS
Search
Yunosuke Yamada
October 16, 2022
Programming
0
290
React and XSS
Yunosuke Yamada
October 16, 2022
Tweet
Share
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
220
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
0
210
ChatGPTのアルゴリズム
yunosukey
0
360
DB Tree Algorithms
yunosukey
0
97
Tests in Go
yunosukey
1
110
Bugless Code
yunosukey
0
130
圏論とコンピュータサイエンス / Category Theory and Theoretical Computer Science
yunosukey
0
270
Other Decks in Programming
See All in Programming
Носок на сок
bo0om
0
1.2k
監視 やばい
syossan27
12
10k
ASP.NETアプリケーションのモダナイゼーションについて
tomokusaba
0
250
파급효과: From AI to Android Development
l2hyunwoo
0
160
Jakarta EE Meets AI
ivargrimstad
0
810
The Implementations of Advanced LR Parser Algorithm
junk0612
2
1.3k
Serving TUIs over SSH with Go
caarlos0
0
590
ComposeでのPicture in Picture
takathemax
0
130
The Nature of Complexity in John Ousterhout’s Philosophy of Software Design
philipschwarz
PRO
0
160
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
ComposeでWebアプリを作る技術
tbsten
0
130
今話題のMCPサーバーをFastAPIでサッと作ってみた
yuukis
0
110
Featured
See All Featured
Building Applications with DynamoDB
mza
94
6.4k
Being A Developer After 40
akosma
91
590k
A Tale of Four Properties
chriscoyier
159
23k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
410
Become a Pro
speakerdeck
PRO
28
5.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
How GitHub (no longer) Works
holman
314
140k
Designing for humans not robots
tammielis
253
25k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Optimising Largest Contentful Paint
csswizardry
37
3.2k
Facilitating Awesome Meetings
lara
54
6.3k
Transcript
ReactとXSS 2021/07/15 山田悠之介
XSS (Cross-site scripting) 悪意のあるスクリプトを閲覧者のブラウザで実行すること 反射型 XSS、格納型 XSS、DOM Based XSS などの種類があるが
いずれも XSS するためには文字列として入力したスクリプトを 標的となるサイトで実行させなければならない 2
React React では XSS 対策として文字列はエスケープされる。 https://ja.reactjs.org/docs/jsx-in-depth.html#string-literals 3
生成される HTML export default function Home() { const script =
` <script> while (1) { alert('!'); } </script>`; return <main>{script}</main>; } ↓ <main><script> while (1) { alert('!'); } </script></main> 4
innerHTML 標準の JS や jQuery で HTML を動的に生成するときには innerHTML を使っていた。
React では... 5
dangerouslySetInnerHTML https://ja.reactjs.org/docs/dom- elements.html#dangerouslysetinnerhtml export default function Home() { const script
= ... const html = { __html: script }; return ( <main> <div dangerouslySetInnerHTML={html} />; </main> ); } 6
href, src export default function Home() { const script =
` javascript: while (1) { alert('!'); }`; return ( <main> <a href={script}>link</a> </main> ); } 7
"javascript:"は deprecated https://reactjs.org/blog/2019/08/08/react- v16.9.0.html#deprecating-javascript-urls 将来的にはエラーにする 8
その他 DOM 要素の取得 (findDOMNode, createRef) からの innerHTML createElement SSR +
Redux eval(React 関係ないけど) 9
回避するには ユーザの入力を無害化する DOMPurify 10
import DOMPurify from "isomorphic-dompurify"; export default function Home() { const
script = "<script>...</script>Hello"; const html = { __html: DOMPurify.sanitize(script) }; return ( <main> <div dangerouslySetInnerHTML={html} /> </main> ); } ↓ <main><div>Hello</div></main> 11
参考資料 https://zenn.dev/yuuhu04/books/xss-anti-pattern-of-react- and-vue 最初に読んだ https://pragmaticwebsecurity.com/articles/spasecurity/react -xss-part1.html part3 まである 網羅的 12
Thank you 13
Otomatik - 172.67.23.78
CloudFlare DNS
Türk Telekom DNS
Google DNS
Open DNS
OSZAR »