← PHP / Laravel · 目次

PHP-057 / 中級

API レスポンスでモデル全体を露出(機密属性を含む)

A01:2021 Broken Access Control · CWE-200 Exposure of Sensitive Information

なぜ問題になるのか?

password、remember_token、内部フラグが JSON に含まれます。

修正方法

php
class User extends Model { protected $hidden = ['password', 'remember_token']; }
return UserResource::collection(User::all());  // API Resource でフィールドを明示

参考資料