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
Transcript
13 slides
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
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
AI時代に成長するエンジニアに必要なスキルとは.pdf
yunosukey
0
330
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
730
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.3k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
2k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
110
AIエージェントのオブザーバビリティについて
yunosukey
1
970
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
1.3k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
510
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
410
Other Decks in Programming
See All in Programming
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
170
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
180
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
150
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
250
AI-Powered Domain-Driven Design
ziobrando
0
470
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
340
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
160
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
690
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
6k
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
200
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
440
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
810
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Between Models and Reality
mayunak
4
590
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Exploring anti-patterns in Rails
aemeredith
4
570
A Tale of Four Properties
chriscoyier
163
24k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Product Roadmaps are Hard
iamctodd
55
13k
Documentation Writing (for coders)
carmenintech
77
5.6k