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
Sessionの衝突から学んだPHPのSession作成方法 @CakeJP 2023/12/...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Hayato Nakamura
December 21, 2023
0
400
Sessionの衝突から学んだPHPのSession作成方法 @CakeJP 2023/12/13 エンジニア小話会 PHPを語り合おう
PHPのSession生成はどのようなアルゴリズムを使っている/使っていたかを調査しました。
Hayato Nakamura
December 21, 2023
Tweet
Share
More Decks by Hayato Nakamura
See All by Hayato Nakamura
定時実行の設定が難しいから、 仕組みで解決をしている話
chikin14niwa
0
110
呼び出し順で、 売上金額を回収できなくした話
chikin14niwa
0
80
N+1はダメなのか? システムを落としたあの日より
chikin14niwa
0
43
重要だけど、 よく忘れる仕様との付き合い方
chikin14niwa
0
98
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
170
Navigating Weather and Climate Data
rabernat
0
97
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
110
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
110
Making Projects Easy
brettharned
120
6.6k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
910
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2k
How to Talk to Developers About Accessibility
jct
2
120
Site-Speed That Sticks
csswizardry
13
1.1k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Transcript
© Cake.jp Co.Ltd. All Right Reserved.|Confidential 2023/12/13 Sessionの衝突から学んだ PHPのSession作成方法
中村隼人
2 © Cake.jp Co.Ltd. All Right Reserved.|Confidential 自己紹介 • 名前
◦ 中村 隼人 • 業務 ◦ カート周り(PHP/Kotlin/TypeScript) • おすすめ🍰 ◦ 毎月タイムセールやってるから買ってね ! ◦ 今これ食べてます!
3 © Cake.jp Co.Ltd. All Right Reserved.|Confidential 話す • PHPのSessionIDの作成方法
話さない • 暗号アルゴリズム • Sessionを使ったプログラムの書き方 • C言語の読み方 今日話すこと/話さないこと
4 © Cake.jp Co.Ltd. All Right Reserved.|Confidential 数秒間で複数回のエラーが発生。 CSからお客様の注文が完了しないという問い合わせが入る。 ある日のこと
5 © Cake.jp Co.Ltd. All Right Reserved.|Confidential ・ユーザとDBデータの紐づけにSessionIDを使っていた。 ・過去(5年前)に生成したSessionIDと現在のSessionIDに衝突が発生した。 ・サービスのコア部分、かつPHP本体への対応が必要だったため、対策方法が難しい。
原因
6 © Cake.jp Co.Ltd. All Right Reserved.|Confidential 32種類の文字列が26桁 → 1.361129468E+39
→ 約136澗(かん) 再現率を調べてみた
7 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHPのセッション作成について
8 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHPのセッション作成について
9 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHPのセッション作成について
10 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHPのセッション作成について 弊社はPHP5.6を使用していた
11 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHP5.6でのSession作成方法
12 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHP5.6でのSession作成方法 Unixタイムスタンプの取得 接続元IPアドレス
+ 時刻 + 乱数 (基本的には数値のみが入る)
13 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHP5.6でのSession作成方法
14 © Cake.jp Co.Ltd. All Right Reserved.|Confidential PHP5.6でのSession作成方法 128bitのバイナリを文字列化(0-9a-v)
15 © Cake.jp Co.Ltd. All Right Reserved.|Confidential OSに用意されている暗号学的にセキュアでランダムな文字列の生成を行っている。 一方のPHP7.1以降では
16 © Cake.jp Co.Ltd. All Right Reserved.|Confidential ある日解決は突然に
17 © Cake.jp Co.Ltd. All Right Reserved.|Confidential • 得られた知見 ◦
最新版への追従は大事! まとめ
18 © Cake.jp Co.Ltd. All Right Reserved.|Confidential https://github.com/php/php-src/blob/4b8f72da5dfb201af4e82dee960261d8657e414f/ext/sessi on/session.c#L287-L434 https://www.php.net/manual/ja/function.session-create-id.php
http://dsas.blog.klab.org/archives/52136166.html 参考資料