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
390
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
260
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
660
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.2k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.9k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
93
AIエージェントのオブザーバビリティについて
yunosukey
1
940
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
1.2k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
480
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
390
Other Decks in Programming
See All in Programming
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
120
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
高専キャリア LT 発表内容
crysta1221
6
5.6k
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
280
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
不幸な GC
chencmd
0
900
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
MIZARU@SPAJAM2026 第二回予選
1901drama
0
110
新卒PdEのリアル
ryu1013
1
480
Foundry Localでエージェント開発
seosoft
0
170
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
140
Family mrubyの進捗
kishima
1
110
Featured
See All Featured
For a Future-Friendly Web
brad_frost
183
10k
Amusing Abliteration
ianozsvald
1
290
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
The Spectacular Lies of Maps
axbom
PRO
1
990
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
Crafting Experiences
bethany
1
320
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
620
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
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