Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
React and XSS
Search
Yunosuke Yamada
October 16, 2022
Programming
410
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React and XSS
Yunosuke Yamada
October 16, 2022
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
AI時代に成長するエンジニアに必要なスキルとは.pdf
yunosukey
0
310
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
680
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.3k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.9k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
100
AIエージェントのオブザーバビリティについて
yunosukey
1
960
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
1.3k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
490
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
400
Other Decks in Programming
See All in Programming
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
480
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
160
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
170
気持ちぃ〜角丸 Squircle
ryu1013
0
290
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
sbt 2.0: takeoff
eed3si9n
0
150
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
16k
AWSに止められる覚悟してますか?
morizo_1984
2
530
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
0
760
SREの越境 / SRE Collaboration
y0hgi
2
300
Featured
See All Featured
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
800
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
560
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Music & Morning Musume
bryan
48
7.4k
The agentic SEO stack - context over prompts
schlessera
0
970
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
600
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Everyday Curiosity
cassininazir
0
350
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
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