ํผ๋๋ก ๋์๊ฐ๊ธฐ
Dev.toSecurity
์๋ฌธ ์ฝ๊ธฐ
ULID ๋์ ์ ํตํ BOLA ๊ณต๊ฒฉ ์ฐจ๋จ ๋ฐ B-Tree ์ธ๋ฑ์ค ์ฑ๋ฅ ์ต์ ํ
Stop BOLA Attacks: Securing Laravel APIs with ULIDs ๐ก๏ธ
AI ์์ฝ
Context
Auto-incrementing Integer PK ์ฌ์ฉ ์ ๋ฐ์ํ๋ ์์ฐจ์ ID ์์ธก ๊ฐ๋ฅ์ฑ์ผ๋ก ์ธํ BOLA ์ทจ์ฝ์ ๋ ธ์ถ. ๋ฌด์์ UUIDv4 ๋์ ์ B-Tree ์ธ๋ฑ์ค์ ๋ฌด์์ ์ฝ์ ์ผ๋ก ์ธํ Disk Fragmentation ๋ฐ Write-amplification ์ฑ๋ฅ ์ ํ ๋ฐ์.
Technical Solution
- ์์ธก ๋ถ๊ฐ๋ฅํ Identifier ํ๋ณด๋ฅผ ํตํ BOLA ๋ฐ Data Scraping ์์ฒ ์ฐจ๋จ
- Timestamp ๊ธฐ๋ฐ ์ ๋ ฌ์ด ๊ฐ๋ฅํ ULID(Universally Unique Lexicographically Sortable Identifier) ์ฑํ
- 26์ ๋ฌธ์์ด ์ค ์ 10์๋ฅผ ๊ณ ์ ๋ฐ Timestamp๋ก ๊ตฌ์ฑํ์ฌ Chronological Order ์ ์ง
- ๋๋จธ์ง 16์์ Cryptographic Randomness๋ฅผ ํตํ ID ์ถ์ธก ๊ฐ๋ฅ์ฑ ์ ๊ฑฐ
- Laravel์ HasUlids Trait๋ฅผ ํ์ฉํ Model Layer ์๋ ์์ฑ ๋ก์ง ๊ตฌํ
- Time-sortable ํน์ฑ์ ์ด์ฉํด created_at ์ปฌ๋ผ ์์ด ID ๊ธฐ๋ฐ์ ๊ณ ์ ์ ๋ ฌ ์ฟผ๋ฆฌ ์ํ
์ค์ฒ ํฌ์ธํธ
- Public-facing API ์ค๊ณ ์ ์ธ๋ถ ๋ ธ์ถ PK์ ์์ฐจ์ ์ ์ ID ์ฌ์ฉ ๊ธ์ง - ๋ฌด์์์ฑ๊ณผ ์ ๋ ฌ ์ฑ๋ฅ์ Trade-off ๋ถ์ ํ UUIDv4 ๋์ ULID ๋๋ UUIDv7 ๊ฒํ - Database Index์ ๋ฌผ๋ฆฌ์ ์ ์ฅ ๊ตฌ์กฐ(B-Tree)๋ฅผ ๊ณ ๋ คํ PK ๋ฐ์ดํฐ ํ์ ์ ์ - API Authorization Middleware์ ๊ฒฐํจ์ ๋ณด์ํ๋ Defense in Depth ์ ๋ต์ผ๋ก Unguessable ID ์ ์ฉ