-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use CSP nonces for script and style tags (#61)
This pull request adds a new `:csp_nonce_assign_key` option to the `error_tracker_dashboard/2` macro. If provided, the error tracker will fetch the nonce from the given assign key and use it in the `<style>` and `<script>` tags. This allows using the ErrorTracker dashboard in environments with a restricted content security policy without requiring the usage of `unsafe-inline`, which should be avoided. This implementation is based on the [Phoenix LiveDashboard](https://hexdocs.pm/phoenix_live_dashboard/Phoenix.LiveDashboard.Router.html#live_dashboard/2) one. I've updated the `dev.exs` script to use CSP headers. If we remove the new option we will see that the ErrorTracker dashboard doesn't have any styles. Closes #58
- Loading branch information
Showing
4 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
defmodule ErrorTracker.Web.Hooks.SetAssigns do | ||
@moduledoc false | ||
|
||
def on_mount({:set_dashboard_path, path}, _params, _session, socket) do | ||
{:cont, %{socket | private: Map.put(socket.private, :dashboard_path, path)}} | ||
import Phoenix.Component, only: [assign: 2] | ||
|
||
def on_mount({:set_dashboard_path, path}, _params, session, socket) do | ||
socket = %{socket | private: Map.put(socket.private, :dashboard_path, path)} | ||
|
||
{:cont, assign(socket, csp_nonces: session["csp_nonces"])} | ||
end | ||
end |
This file contains 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