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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
210
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
620
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.2k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.7k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
81
AIエージェントのオブザーバビリティについて
yunosukey
1
910
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
1.1k
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
460
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
370
Other Decks in Programming
See All in Programming
Performance Engineering for Everyone
elenatanasoiu
0
270
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
250
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.4k
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
350
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
350
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
310
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
130
霧の中の代数的エフェクト
funnyycat
1
340
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.4k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.8k
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Become a Pro
speakerdeck
PRO
31
6k
Visualization
eitanlees
152
17k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Design in an AI World
tapps
1
260
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
490
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Context Engineering - Making Every Token Count
addyosmani
9
1k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
320
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