背景与价值 设备与传感器权限具有隐私敏感性。统一在响应头限制并按白名单逐项开启,可有效降低风险。 统一规范 - 默认禁用:`camera=(); microphone=(); geolocation=(); accelerometer=(); gyroscope=(); magnetometer=()`。 - 例外开启:针对受控来源与页面按需开启。 - 审计:记录权限命中与拒绝。 核心实现 头设置 ```ts type Res = { setHeader: (k: string, v: string) => void } function setPermissions(res: Res, allow: { camera?: string[]; microphone?: string[]; geolocation?: string[]; accelerometer?: string[]; gyroscope?: string[]; magnetometer?: string[] } = {}) { function fmt(name: string, list?: string[]): string { if (!list || list.length === 0) return `${name}=()`; return `${name}=( ${list.map(o => `"${o}"`).join(' ')} )` } const v = [ fmt('camera', allow.camera), fmt('microphone', allow.microphone), fmt('geolocation', allow.geolocation), fmt('accelerometer', allow.accelerometer), fmt('gyroscope', allow.gyroscope), fmt('magnetometer', allow.magnetometer) ].join(', ') res.setHeader('Permissions-Policy', v) } ``` 落地建议 - 全站默认禁用,针对受控页面按来源白名单开启必要权限;最小化粒度与范围。 - 持续审计与复核权限使用,收敛不必要的访问能力。 验证清单 - 是否统一下发禁用策略;例外是否仅限受控来源并按需开启。
点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿
网站二维码

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
/* 跳过导航链接 (无障碍) */ position: absolute; top: -100px; left: 15px; z-index: 99999; padding: 8px 16px; background: #007bff; color: #fff; font-size: 14px; border-radius: 0 0 4px 4px; text-decoration: none; transition: top 0.2s; } top: 0; outline: 3px solid #0056b3; }