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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yunosuke Yamada
October 16, 2022
Programming
370
0
Share
React and XSS
Yunosuke Yamada
October 16, 2022
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
AI時代に成長するエンジニアに必要なスキルとは.pdf
yunosukey
0
180
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
580
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.1k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.6k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
70
AIエージェントのオブザーバビリティについて
yunosukey
1
880
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
1k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
440
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
350
Other Decks in Programming
See All in Programming
The Less-Told Story of Socket Timeouts
coe401_
3
1.1k
PHPでローカル環境用のSSL/TLS証明書を発行することはできるのか? #phpconkagawa
akase244
0
350
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
140
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.6k
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
2026年のソフトウェア開発を考える(2026/05版) / Software Engineering Scrum Fest Niigata 2026 Edition
twada
PRO
22
12k
Kingdom of the Machine
yui_knk
2
1.5k
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
140
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
150
AIを導入する前にやるべきこと
negima
2
340
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
250
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
770
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
250
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
550
The Language of Interfaces
destraynor
162
26k
Evolving SEO for Evolving Search Engines
ryanjones
0
190
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
340
The Spectacular Lies of Maps
axbom
PRO
1
740
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
Navigating Team Friction
lara
192
16k
The Pragmatic Product Professional
lauravandoore
37
7.3k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
Designing for humans not robots
tammielis
254
26k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
910
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