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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yunosuke Yamada
October 16, 2022
Programming
370
0
Share
React and XSS
Yunosuke Yamada
October 16, 2022
More Decks by Yunosuke Yamada
See All by Yunosuke Yamada
AI時代に成長するエンジニアに必要なスキルとは.pdf
yunosukey
0
160
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
530
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1.1k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.6k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
67
AIエージェントのオブザーバビリティについて
yunosukey
1
870
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
970
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
430
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
350
Other Decks in Programming
See All in Programming
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
110
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
140
Running Swift without an OS
kishikawakatsumi
0
840
Coding as Prompting Since 2025
ragingwind
0
830
JAWS-UG横浜 #100 祝・第100回スペシャルAWS は VPC レスの時代へ
maroon1st
0
150
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
140
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
6.5k
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
950
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
340
VueエンジニアがReactを触って感じた_設計の違い
koukimiura
0
180
AIエージェントで業務改善してみた
taku271
0
530
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
900
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
260
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
Mind Mapping
helmedeiros
PRO
1
150
Visualization
eitanlees
150
17k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
270
Optimizing for Happiness
mojombo
378
71k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
94
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
310
Test your architecture with Archunit
thirion
1
2.2k
WENDY [Excerpt]
tessaabrams
10
37k
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