Repository navigation
Enforce the compatibility CSP by default and stop allowing eval - #35
Merged
Merged
Conversation
The CSP was report-only, so it blocked nothing and scanners treated the site as having no policy. The E2E inventory found no eval use, and none of the loaded frontend assets call eval or new Function, so drop 'unsafe-eval' from the compat policy and enforce it by default. CSP_MODE=report-only remains as an immediate rollback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSP 收斂第 1 步。原本 CSP 只有 report-only,實際上不阻擋任何內容,黑箱掃描(AppScan)通常視為未設定 CSP;政策也允許
'unsafe-eval'。修改:
CSP_MODE預設由report-only改為enforce。compat政策移除'unsafe-eval',仍允許 inline script/style(YiiregisterJs、AdminLTE 需要),畫面行為不變。CSP_MODE=report-only保留為立即還原手段,只要改.env,不需重新部署。.env.example、SECURITY.md、SETUP.md 部署檢查表、威脅模型、E2E README 已更新。移除
'unsafe-eval'的依據:frontend/、kartik、Yii、jQuery、Bootstrap、AdminLTE dist、select2,含壓縮檔)皆未使用eval或new Function。唯一命中的是 AdminLTE 內附但本系統未載入的 dropzone、inputmask、pdfmake。仍有的限制:E2E 未涵蓋的畫面可能有未知依賴。正式環境若發現功能被擋,可設
CSP_MODE=report-only。驗證(dev6,PHP 8.2.35,HEAD
dad75b9,測試伺服器不設任何 CSP 變數,也就是使用新預設):Content-Security-Policy(強制),script-src 'self' 'unsafe-inline'。SecurityHeadersBootstrapTest13 tests/27 assertions 通過。下一步(另開 PR):為
registerJs加 nonce、將 6 種 inline 事件處理改為事件監聽,移除script-src 'unsafe-inline'。🤖 Generated with Claude Code