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
CSP による防御とリアルワールドレポート収集/csp-and-real-world-repo...
Search
Jxck
February 03, 2017
Technology
5
4.5k
CSP による防御とリアルワールドレポート収集/csp-and-real-world-reporting
Recruit Tech Night #rtechnight 2017/2/3
Jxck
February 03, 2017
Tweet
Share
More Decks by Jxck
See All by Jxck
IE Graduation (IE の功績を讃える)
jxck
22
16k
IE Graduation Certificate
jxck
6
6.2k
RFC 9111: HTTP Caching
jxck
1
740
tc39_study_2
jxck
1
13k
IETF における ABNF とプロトコルパーサの話 / ABNF for Protocol Parser @ IETF
jxck
2
1.2k
Web Components 元年 v3 / Web Components first year v3
jxck
1
1.1k
Periodic Background Sync
jxck
0
600
Podcast over PWA
jxck
0
300
Yearly Web 2019
jxck
0
220
Other Decks in Technology
See All in Technology
国産クラウドを支える設計とチームの変遷 “技術・組織・ミッション”
kazeburo
4
8.4k
重厚長大企業で、顧客価値をスケールさせるためのプロダクトづくりとプロダクト開発チームづくりの裏側 / Developers X Summit 2025
mongolyy
0
190
技術広報のOKRで生み出す 開発組織への価値 〜 カンファレンス協賛を通して育む学びの文化 〜 / Creating Value for Development Organisations Through Technical Communications OKRs — Nurturing a Culture of Learning Through Conference Sponsorship —
pauli
5
530
pmconf 2025 大阪「生成AI時代に未来を切り開くためのプロダクト戦略:圧倒的生産性を実現するためのプロダクトサイクロン」 / The Product Cyclone for Outstanding Productivity
yamamuteki
3
2.5k
How We Built a Secure Sandbox Platform for AI
flatt_security
1
110
AI駆動開発2025年振り返りとTips集
knr109
1
100
ABEMAのCM配信を支えるスケーラブルな分散カウンタの実装
hono0130
4
1.1k
[CV勉強会@関東 ICCV2025 読み会] World4Drive: End-to-End Autonomous Driving via Intention-aware Physical Latent World Model (Zheng+, ICCV 2025)
abemii
0
250
.NET 10のEntity Framework Coreの新機能
htkym
0
120
AI開発の定着を推進するために揃えるべき前提
suguruooki
1
140
TypeScript 6.0で非推奨化されるオプションたち
uhyo
15
5k
社内外から"使ってもらえる"データ基盤を支えるアーキテクチャの秘訣/登壇資料(飯塚 大地・高橋 一貴)
hacobu
PRO
0
6.5k
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Building an army of robots
kneath
306
46k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Code Reviewing Like a Champion
maltzj
527
40k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Mobile First: as difficult as doing things right
swwweet
225
10k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
BBQ
matthewcrist
89
9.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
RailsConf 2023
tenderlove
30
1.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.1k
Transcript
CSP real world reporting Recruit Tech Night #rtechnight 2017/02/03
Jack
P rotein S teroid 3 C ontent
4 C ontent S teroid P rotein S ecurity P
olicy
5
6 Policy of Security for Content • This content is
allowed to ◦ exec inline script ? ◦ load assets from origin xxx ? ◦ embend iframe ? ◦ mixed content ? ◦ etc
7 How to apply CSP • via Header • via
Meta Tag Content-Security-Policy: $policy <meta http-equiv=”Content-Security-Policy” content=”$policy” >
8 CSP directives • connect-src • font-src • frame-src •
img-src • manifest-src • media-src • object-src • script-src • style-src • worker-src どこから読み込めるかの設定 ex) img-src ‘self’ https://jxck.io (同じ Origin と https://jxck.io のみ画像を許可) default-src は指定しない場合のフォー ルバックとして働く。
9 CSP keywords • ‘self’ • ‘none’ • ‘unsafe-inline’ •
‘unsafe-eval’ <script>, <style> を利用した インラインの実行や、 eval 自 体もブロックされるため、明示 的に許可するには unsafe-* を 使う。
10 Most Powerful Policy • can I have… ◦ jquery
from cdn ? :No ◦ google anlytics ? :No ◦ youtube? :No ◦ iframe... :NO! ◦ inli :Never !! Content-Security-Policy: default-src ‘self’
11 Example: XSS <meta http-equiv="Content-Security-Policy" content="default-src 'self'">
No more Escape Input ? • 本質的に攻撃を防いでいるわけではない ◦ CSP に対応してないクライアントもある
• ポリシー違反を不活性にするだけ ◦ ポリシーに穴があれば攻撃は成り立つ • これまでのセキュリティ対策との合わせ技 ◦ 防ぎきれなかった攻撃を不活性にする最後の砦 12
13 case study: github.com
It’s really works ?? 14
report-uri 15 • Send Report as JSON to URI Content-Security-Policy:
default-src ‘self’; report-uri https://report-server/... { "csp-report": { "document-uri": "発生場所", "referrer": "リファラ", "blocked-uri": "防いだもの", "violated-directive": "違反していたディレクティブ ", "original-policy": "元となるポリシー", } }
Report doesn’t tells me about attack • 何が起こったかは分かる ◦ ブロックされたもの
◦ それを引きおこしたポリシー • どうして起こったかはわからない ◦ 攻撃か?それ以外か? • その結果ユーザがどういう体験をしたかもわかりにくい ◦ 広告が見えなかった? ◦ 登録ができなかった? 16
It’s really… OK ...? 17
Too strict to deploy immediate • ポリシーが妥当かをチェックするのは難しい ◦ ステージングなどでやってみるしかない •
リアルワールドでの使われ方は多様 ◦ どんなブラウザをどんな設定で使ってるか不明 • いきなり本番で有効にするのは怖い ◦ ユーザが不都合な現象に出会わないか。。 ◦ 攻撃が発生するよりも怖いかもしれない。。 18
CSP-Report-Only • CSP を適用するがブロックはしない ◦ レポートを送るだけ ◦ 実際にどんなレポートが来るかを解析できる • いつ外すか?
◦ ポリシーに自身が持てたら ◦ 無理に Report-Only を外す必要もないかも ◦ 何が起こってるか分かるだけでも前進してる 19
一年ほどやってみた 20
blog.jxck.io 21 • basically static contents only ◦ no <input>
◦ no Dynamic Generated ◦ no CDN • 基本的に XSS などの発生は考えにくい ◦ その条件でもレポートがあるのか ◦ あるとすればどんなものかを調査 ◦ <input> があるサービスではもっと増えるだろう
Current Settings 22 content-security-policy-report-only: default-src 'self' https://jxck.io https://*.jxck.io https://www.google-analytics.co m
; child-src https://blog.jxck.io https://www.youtube.com ; connect-src wss://ws.jxck.io ; report-uri https://jxck.report-uri.io/...
23 CSP report (2016/3 ~ now) deploy fixup csp setting
non critical reports
24 CSP Report case#1 • inline style in FF view-source://
{ "csp-report": { "blocked-uri": "self", "document-uri": "view-source", "original-policy": "...", "script-sample": "-moz-tab-size: 4", "source-file": "view-source:https://blog.jxck.io/entries/...", "violated-directive": "default-src view-source:// ..." } }
25 CSP Report case#1 • inline style in FF view-source://
26 CSP Report case#2 • inline style in Chrome .txt,
.md, .xml { "csp-report": { "document-uri": "https://jxck.io/humans.txt", "referrer": "", "violated-directive": "style-src", "effective-directive": "style-src", "original-policy":"default-src 'self' https://*.jxck.io...", "disposition":"report", "blocked-uri":"inline", "line-number":1, "status-code":0 } }
27 CSP Report case#2 • inline style in Chrome .txt,
.md, .xml
28 CSP Report case#3 • about://blank { "csp-report": { "document-uri":
"about://blank", "violated-directive": "default-src 'self' https://jxck.io...", "effective-directive": "img-src", "original-policy": "default-src 'self' https://jxck.io…", "blocked-uri": "data", "status-code": 0 } }
29 CSP Report case#2 • browser-extension { "csp-report": { "document-uri":
"https://blog.jxck.io/entries/...", "violated-directive": "default-src 'self' https://jxck.io ...", "effective-directive": "img-src", "original-policy": "default-src 'self' https://jxck.io ...", "blocked-uri": "ms-browser-extension", "status-code": 0 } }
30 CSP Report case#2 • append script via bookmarklet (maybe)
{ "csp-report": { "document-uri": "https://blog.jxck.io/entries/...", "referrer": "https://blog.jxck.io/", "violated-directive": "script-src", "effective-directive": "script-src", "original-policy": "default-src 'self' https://jxck.io...", "disposition": "report", "blocked-uri": "https://code.jquery.com/jquery-3.0.0.min.js", "line-number": 1, "column-number": 108, "status-code": 0 } }
More and More... 31
32 Protected? / Clippled? • ほとんどの違反は攻撃には見えない ◦ 本当に全部ブロックすべき? ◦ ユーザに不便を強いてないか?
• 基本的に開発者向けのサイト ◦ コンテンツはいじられる前提 ◦ bookmarklets, extentions, localproxy etc ◦ レポート収集くらいがちょうど良さそう • Protected / Clippled ◦ コンテンツ次第としか言えない ◦ Github は思い切ってるなぁ
Mixed Contents 33
Finding Mixed Contents 34 • Mixed Contents ◦ HTTPS コンテンツ内で
HTTP コンテンツを読み込む ◦ MITM されてるかもしれない(安全を保証できない) ◦ URL バーが緑ではなくなる • Active ◦ 元の DOM を書き換えられる(script, iframe etc) ◦ ブロックされる • Passive ◦ 元の DOM は書き換えられない(img, video, audio etc) ◦ エラーはでるがブロックされない
HTTPS 移行と Mixed Contents 35 • Mixed Contents のよくあるパターン ◦
Consumer Generated Media (ユーザの埋めた img など) ◦ Ad (広告の iframe など) ◦ Legacy Hard Coded URL (古い新聞社 など) • 勢いで HTTPS 移行すると ◦ insecure 表示になって信用を失う ◦ ユーザの作ったコンテンツが壊れる ◦ 広告が見えなくて収入がががが ◦ 全部の URL 書き換えるの、、マジ無理、、
Upgrade-Insecure-Request 36 • http:// を https:// にブラウザが読み換える ◦ https:// がなければ
404 になる ◦ ただし、絶対に mixed contents にならない • サーバの対応だけで移行できる ◦ コンテンツを書き換えないで良い ◦ https にできてないものを access.log で見つけられる Content-Security-Policy: Upgrade-Insecure-Requests
Block-All-Mixed-Contents 37 • Passive でもブロックする ◦ コンテンツは壊れるかもしれない ◦ ただし、絶対に mixed
contents にならない • CSP Report と組み合わせられる ◦ Report-Only にすればコンテツに影響が出ない ◦ https にできてないものを csp reoprt で見つけられる Content-Security-Policy: Block-All-Mixed-Contents
Report Server 38
39 report-uri.io • not recommended (personaly) ◦ UI が ◦ソ
◦ 同時に Report をたくさん送ると 500 返すことが ◦ 半年以前のデータが表示できない? ◦ HTTP ヘッダが見えないので UA がわからない ◦ 過去のレポートをエクスポートできない • do yourself ◦ POST 受け取るシンプルなエンドポイントでよい ◦ 処理は kibana, grafana, big query などで ◦ Google Analytics がやってくれると嬉しい
40 Report Analyze • ほとんどが設定ミス ◦ ステージングとプロダクションで分けよう ◦ フレームワーク/CMS での自動化に期待
• Attacks を見つけるのは難しい ◦ 難、、無理じゃね? ◦ でも傾向には価値がある ◦ AI とかに期待
One More Thing 41
HTTP Public Key Pinning 42 • 意図してない公開鍵での表示を防ぐ ◦ CA インシデントの多発により提案された
◦ 主に Google が怒って入れた • 運用が難しい ◦ 証明書が変わると表示されなくなる場合も ◦ バックアップのハッシュを事前にやっておくべき Public-Key-Pins: pin-sha256=”#{hash-of-public-key}”
さすがに来ないだろ 43
来た 44
this is Real World Web 45
May the Safe be with Web 46
Jack