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
Yunosuke Yamada
October 16, 2022
Programming
0
330
React and XSS
Yunosuke Yamada
October 16, 2022
Tweet
Share
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
160
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
540
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.2k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
36
AIエージェントのオブザーバビリティについて
yunosukey
1
770
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
740
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
340
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
290
ChatGPTのアルゴリズム
yunosukey
0
390
Other Decks in Programming
See All in Programming
TransformerからMCPまで(現代AIを理解するための羅針盤)
mickey_kubo
4
2.2k
Pythonに漸進的に型をつける
nealle
1
110
Webサーバーサイド言語としてのRustについて
kouyuume
1
3.7k
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
420
Range on Rails ―「多重範囲型」という新たな選択肢が、複雑ロジックを劇的にシンプルにしたワケ
rizap_tech
0
6.7k
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
16
6.5k
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
110
Leading Effective Engineering Teams in the AI Era
addyosmani
7
560
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
120
Domain-centric? Why Hexagonal, Onion, and Clean Architecture Are Answers to the Wrong Question
olivergierke
3
940
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
520
デミカツ切り抜きで面倒くさいことはPythonにやらせよう
aokswork3
0
250
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4k
For a Future-Friendly Web
brad_frost
180
10k
The World Runs on Bad Software
bkeepers
PRO
72
11k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
Building an army of robots
kneath
306
46k
Rails Girls Zürich Keynote
gr2m
95
14k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
22k
What's in a price? How to price your products and services
michaelherold
246
12k
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