phpinfo() doesn't play nicely with strict CSPs
還沒有人認領這個 Issue。
- 主要語言
- C
- 星號
- 40.4k
- 分支
- 8.1k
- 平均合併
- 2 天 13 小時
- 30 天內合併 PR
- 96
描述
Description
The output generated by phpinfo() includes inline styles and data: URLs for two images. While this is self-contained, it's incompatible with Content-Security-Policy headers that are configured securely, specifically, if your CSP doesn't include 'unsafe-inline' for style-src and data: for img-src, the output looks bad:
Two of the 6 locations in the output (i.e. not many) that uses inline styles:
<tr>
<td class="e">highlight.comment</td>
<td class="v">
<span style="color: #FF8000">#FF8000</span>
</td>
<td class="v">
<span style="color: #FF8000">#FF8000</span>
</td>
</tr>
styling like this would need to be turned into classes, though as you can see this output already makes use of classes, so this is trivial to fix.
A good way to resolve this would be to extend phpinfo so that it can serve these resources separately depending on the request context, so for example a request that contains a request param like phpinfo=styles could serve the style sheet, and phpinfo=logo could serve a logo image.
This approach would be compatible with a super-strict CSP like this (in fact there's nothing preventing phpinfo from generating this header itself):
Content-Security-Policy: default-src 'none'; image-src 'self'; style-src 'self';
The downside of this approach is that it would end up making multiple requests to serve the same page content. I don't know if there is a way that the existing approach could be preserved while allowing for this more secure approach as well.
An alternative would be for the page to generate CSP nonces or SRI hashes for the data and style elements. That's probably more complicated, though it would allow the page to remain self-contained.
Since phpinfo is a development feature, it's not very important to fix this, but it's an easy opportunity to encourage secure development practices while also making the generated page immune to injections.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 phpinfo() 入口點開始,追蹤其 HTML、內嵌樣式和 data: 圖片 URL 的產生方式。將可能的資源提供方案以及 nonce 或 hash 方案與 issue 中描述的嚴格 CSP 進行比較。完成標準是產生的頁面在不允許 unsafe-inline 或 data: 的情況下能正確呈現。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, php
- 領域
- backend, security
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 35/100