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
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
140
Gemini CLIでもセキュアで堅牢な開発をしたい!
yunosukey
1
440
DevOps/MLOpsに学ぶエージェントの可観測性
yunosukey
1
1k
Agent Development Kitで作るマルチエージェントアプリケーション(AIAgent勉強会)
yunosukey
4
1.5k
Agent Development Kitで作るマルチエージェントアプリケーション(GCNT2025)
yunosukey
0
60
AIエージェントのオブザーバビリティについて
yunosukey
1
850
OpenTelemetry + LLM = OpenLLMetry!?
yunosukey
2
940
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
410
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
1
340
Other Decks in Programming
See All in Programming
SourceGeneratorのマーカー属性問題について
htkym
0
200
安いハードウェアでVulkan
fadis
0
300
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
210
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
220
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
230
最初からAWS CDKで技術検証してもいいんじゃない?
akihisaikeda
4
160
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
470
The free-lunch guide to idea circularity
hollycummins
0
270
Windows on Ryzen and I
seosoft
0
320
AIコードレビューの導入・運用と AI駆動開発における「AI4QA」の取り組みについて
hagevvashi
0
500
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.4k
AI活用のコスパを最大化する方法
ochtum
0
140
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
640
Tell your own story through comics
letsgokoyo
1
850
Color Theory Basics | Prateek | Gurzu
gurzu
0
250
Technical Leadership for Architectural Decision Making
baasie
3
290
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
480
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
170
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
480
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Skip the Path - Find Your Career Trail
mkilby
1
82
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Speed Design
sergeychernyshev
33
1.6k
We Are The Robots
honzajavorek
0
200
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