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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yunosuke Yamada
October 16, 2022
Programming
380
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
190
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
610
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.1k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.7k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
75
AIエージェントのオブザーバビリティについて
yunosukey
1
900
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
1.1k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
450
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
360
Other Decks in Programming
See All in Programming
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
130
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
110
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
200
Lessons from Spec-Driven Development
simas
PRO
0
150
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
100
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
510
Modding RubyKaigi for Myself
yui_knk
0
910
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.5k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.9k
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
260
Oxcを導入して開発体験が向上した話
yug1224
4
300
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
950
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
400
Making the Leap to Tech Lead
cromwellryan
135
9.9k
WCS-LA-2024
lcolladotor
0
620
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
550
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
380
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Evolving SEO for Evolving Search Engines
ryanjones
0
210
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