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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yunosuke Yamada
October 16, 2022
Programming
0
360
React and XSS
Yunosuke Yamada
October 16, 2022
Tweet
Share
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
AI時代に成長するエンジニアに必要なスキルとは.pdf
yunosukey
0
120
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
420
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
960
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.5k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
57
AIエージェントのオブザーバビリティについて
yunosukey
1
840
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
910
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
410
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
340
Other Decks in Programming
See All in Programming
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.5k
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
190
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
240
ご飯食べながらエージェントが開発できる。そう、Agentic Engineeringならね。
yokomachi
1
260
Rubyと楽しいをつくる / Creating joy with Ruby
chobishiba
0
190
AI時代の認知負荷との向き合い方
optfit
0
180
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
460
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
PRO
0
190
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
180
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
350
日本だけで解禁されているアプリ起動の方法
ryunakayama
0
360
Package Management Learnings from Homebrew
mikemcquaid
0
280
Featured
See All Featured
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
180
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
The Cost Of JavaScript in 2023
addyosmani
55
9.7k
Git: the NoSQL Database
bkeepers
PRO
432
66k
The SEO identity crisis: Don't let AI make you average
varn
0
400
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
My Coaching Mixtape
mlcsv
0
60
We Are The Robots
honzajavorek
0
180
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
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