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
ALB ログから Trace を気合で繋げる技術
fohte
7
880
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
490
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
120
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
56
37k
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
370
Deep dive into the select statement (GopherCon UK)
jespino
0
170
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
210
Security issues being discussed on Web Platforms
petamoriken
0
670
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
130
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
170
Featured
See All Featured
Building Adaptive Systems
keathley
44
3.2k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
320
Into the Great Unknown - MozCon
thekraken
41
2.7k
We Have a Design System, Now What?
morganepeng
55
8.3k
Six Lessons from altMBA
skipperchong
29
4.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
It's Worth the Effort
3n
188
29k
Exploring anti-patterns in Rails
aemeredith
3
500
Are puppies a ranking factor?
jonoalderson
2
3.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
780
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