Skip to content

Commit 62dd932

Browse files
authored
Merge pull request #76 from ElixirCLE/add-games-to-users
Sanitize user names so they don't break pages
2 parents 56ac669 + ac9da44 commit 62dd932

File tree

6 files changed

+9
-4
lines changed

6 files changed

+9
-4
lines changed

mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ defmodule Nermesterts.Mixfile do
4141
{:phoenix, "~> 1.2.0"},
4242
{:phoenix_ecto, "~> 3.0"},
4343
{:phoenix_html, "~> 2.6"},
44+
{:phoenix_html_sanitizer, "~> 1.1"},
4445
{:phoenix_live_reload, "~> 1.0", only: :dev},
4546
{:phoenix_pubsub, "~> 1.0"},
4647
{:postgrex, ">= 0.0.0"},

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"phoenix": {:hex, :phoenix, "1.2.4", "4172479b5e21806a5e4175b54820c239e0d4effb0b07912e631aa31213a05bae", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.4 or ~> 1.3.3 or ~> 1.2.4 or ~> 1.1.8 or ~> 1.0.5", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]},
3030
"phoenix_ecto": {:hex, :phoenix_ecto, "3.2.3", "450c749876ff1de4a78fdb305a142a76817c77a1cd79aeca29e5fc9a6c630b26", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, optional: true]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}]},
3131
"phoenix_html": {:hex, :phoenix_html, "2.9.3", "1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]},
32+
"phoenix_html_sanitizer": {:hex, :phoenix_html_sanitizer, "1.1.0", "ea9e1162217621208ba6b2951a24abe2c06b39347f65c22c31312f9f5ac0fa75", [:mix], [{:html_sanitize_ex, "~> 1.1", [hex: :html_sanitize_ex, optional: false]}, {:phoenix_html, "~> 2.0", [hex: :phoenix_html, optional: false]}]},
3233
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.8", "4333f9c74190f485a74866beff2f9304f069d53f047f5fbb0fb8d1ee4c495f73", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, optional: false]}]},
3334
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], []},
3435
"plug": {:hex, :plug, "1.3.5", "7503bfcd7091df2a9761ef8cecea666d1f2cc454cbbaf0afa0b6e259203b7031", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},

web/templates/layout/app.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li role="presentation"><%= link "Phrases", to: phrase_path(@conn, :index)%></li>
2424
<li role="presentation"><%= link "Games", to: game_path(@conn, :index)%></li>
2525
<li class="dropdown" role="presentation">
26-
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <%= current_user_name(@conn) %> <span class="caret"></span></a>
26+
<a href="#" class="dropdown-toggle" data-html="true" data-toggle="dropdown"> <%= sanitize(current_user_name(@conn)) %> <span class="caret"></span></a>
2727
<ul class="dropdown-menu">
2828
<%= if logged_in?(@conn) do %>
2929
<li><%= link "Edit", to: user_path(@conn, :edit, current_user(@conn))%></li>

web/templates/user/index.html.eex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<tbody>
1111
<%= for user <- @active_players do %>
1212
<tr>
13-
<td><%= User.display_name(user) %></td>
13+
<td><%= sanitize(User.display_name(user)) %></td>
1414

1515
<td class="text-right">
1616
<%= if logged_in?(@conn) do %>
@@ -43,7 +43,7 @@
4343
<tbody>
4444
<%= for user <- @inactive_players do %>
4545
<tr>
46-
<td><%= User.display_name(user) %></td>
46+
<td><%= sanitize(User.display_name(user)) %></td>
4747

4848
<td class="text-right">
4949
<%= if logged_in?(@conn) do %>

web/views/game_view.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ defmodule Nermesterts.GameView do
1717
end
1818

1919
defp generate_owner_list([user|users]) do
20-
"<li>" <> User.display_name(user) <> "</li>" <> generate_owner_list(users)
20+
{:safe, safe_name} = sanitize(User.display_name(user), :strip_tags)
21+
{:safe, safe_name} = html_escape(safe_name)
22+
"<li>" <> safe_name <> "</li>" <> generate_owner_list(users)
2123
end
2224
defp generate_owner_list([]) do
2325
""

web/web.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ defmodule Nermesterts.Web do
5151

5252
# Use all HTML functionality (forms, tags, etc)
5353
use Phoenix.HTML
54+
use PhoenixHtmlSanitizer, :basic_html
5455

5556
import Nermesterts.Router.Helpers
5657
import Nermesterts.ErrorHelpers

0 commit comments

Comments
 (0)