← PHP / Laravel · 目录

PHP-057 / 中级

API 响应暴露整个模型(含敏感属性)

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

为什么存在问题?

JSON 中包含 password、remember_token 及内部标志。

如何修复

php
class User extends Model { protected $hidden = ['password', 'remember_token']; }
return UserResource::collection(User::all());  // 通过 API Resource 明确字段

延伸阅读