Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XSS exploit in metadata_url #1107

Merged
merged 8 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/blockscout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ jobs:

- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ESLint Test Results
path: apps/block_scout_web/assets/test/eslint/*.xml
Expand Down Expand Up @@ -348,7 +348,7 @@ jobs:

- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Jest JUnit Test Results
path: apps/block_scout_web/assets/junit.xml
Expand Down Expand Up @@ -417,7 +417,7 @@ jobs:
ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox"
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: EthereumJSONRPC Test Results
path: _build/test/junit/ethereum_jsonrpc/*.xml
Expand Down Expand Up @@ -506,7 +506,7 @@ jobs:
ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox"
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Explorer Test Results
path: _build/test/junit/explorer/*.xml
Expand Down Expand Up @@ -578,7 +578,7 @@ jobs:
ETHEREUM_JSONRPC_WEB_SOCKET_CASE: "EthereumJSONRPC.WebSocket.Case.Mox"
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Indexer Test Results
path: _build/test/junit/indexer/*.xml
Expand Down Expand Up @@ -687,14 +687,14 @@ jobs:
API_V2_ENABLED: "true"
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Blockscout Web Test Results
path: _build/test/junit/block_scout_web/*.xml

- name: Upload Wallaby screenshots
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Wallaby screenshots
path: apps/block_scout_web/screenshots/*.png
Expand All @@ -718,7 +718,7 @@ jobs:
path: artifacts

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: artifacts/**/*.xml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do

def external_url(nil), do: nil

def external_url("http" <> _rest = external_url), do: external_url
def external_url("http" <> _rest = external_url) do
sanitised = external_url |> html_escape() |> safe_to_string()

if sanitised != external_url do
nil
else
external_url
end
end

def external_url(string) when is_binary(string), do: external_url(nil)

Expand Down
4 changes: 2 additions & 2 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ msgstr ""

#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:202
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:210
#, elixir-autogen, elixir-format
msgid "Metadata"
msgstr ""
Expand Down Expand Up @@ -2659,7 +2659,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:434
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:201
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:209
#: lib/block_scout_web/views/tokens/overview_view.ex:39
#: lib/block_scout_web/views/transaction_view.ex:535
#, elixir-autogen, elixir-format
Expand Down
4 changes: 2 additions & 2 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ msgstr ""

#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:202
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:210
#, elixir-autogen, elixir-format
msgid "Metadata"
msgstr ""
Expand Down Expand Up @@ -2659,7 +2659,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:434
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:201
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:209
#: lib/block_scout_web/views/tokens/overview_view.ex:39
#: lib/block_scout_web/views/transaction_view.ex:535
#, elixir-autogen, elixir-format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewViewTest do
assert result == nil, "non http url schemes should be stripped from external_url and treated as missing"
end

test "does not return html escape" do
data = %{
"external_url" => "https\" id=x tabindex=1 onfocusin=eval(atob('KGZ1bmN0aW9uKCl7d2luZG93LmV0aG'))"
}

result = OverviewView.external_url(%{metadata: data})

assert result == nil, "non http url schemes should be stripped from external_url and treated as missing"
end

test "Returns valid uri scheme" do
json = """
{
Expand All @@ -153,6 +163,7 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewViewTest do
result = OverviewView.external_url(%{metadata: data})

assert String.starts_with?(result, "http"), "Valid url should be returned"
assert result == "https://happyland.nft"
end
end
end
Loading