Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Sessionの衝突から学んだPHPのSession作成方法 @CakeJP 2023/12/...
Search
Hayato Nakamura
December 21, 2023
460
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Sessionの衝突から学んだPHPのSession作成方法 @CakeJP 2023/12/13 エンジニア小話会 PHPを語り合おう
PHPのSession生成はどのようなアルゴリズムを使っている/使っていたかを調査しました。
Hayato Nakamura
December 21, 2023
More Decks by Hayato Nakamura
See All by Hayato Nakamura
定時実行の設定が難しいから、 仕組みで解決をしている話
chikin14niwa
0
130
呼び出し順で、 売上金額を回収できなくした話
chikin14niwa
0
110
N+1はダメなのか? システムを落としたあの日より
chikin14niwa
0
79
重要だけど、 よく忘れる仕様との付き合い方
chikin14niwa
0
130
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
55
13k
Rails Girls Zürich Keynote
gr2m
96
14k
Designing Experiences People Love
moore
143
24k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Statistics for Hackers
jakevdp
799
230k
A Tale of Four Properties
chriscoyier
163
24k
sira's awesome portfolio website redesign presentation
elsirapls
0
410
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.2k
Exploring anti-patterns in Rails
aemeredith
4
510
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
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 参考資料