Skip to content

Commit

Permalink
Sanitize query input
Browse files Browse the repository at this point in the history
  • Loading branch information
vbaranov committed Mar 29, 2024
1 parent 60c0554 commit 050aac3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/absinthe/plug/graphiql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,11 @@ defmodule Absinthe.Plug.GraphiQL do
defp normalize_socket_url(%{socket_url: url} = config, _) do
%{config | socket_url: "'#{url}'"}
end

defp sanitize(input) do
input
|> to_string()
|> Plug.HTML.html_escape()
|> String.replace(""", "\"")
end
end
2 changes: 1 addition & 1 deletion lib/absinthe/plug/graphiql/graphiql.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ add "&raw" to the end of the URL within a browser.
fetcher,
onEditQuery: onEditQuery,
onEditVariables: onEditVariables,
query: '<%= query_string %>',
query: '<%= sanitize(query_string) %>',
response: '<%= result_string %>',
variables: '<%= variables_string %>',
}),
Expand Down
2 changes: 1 addition & 1 deletion lib/absinthe/plug/graphiql/graphiql_workspace.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ add "&raw" to the end of the URL within a browser.
defaultWebsocketUrl: <%= socket_url %>,
subscriptionsClientBuilder: absintheSubscriptionsClientBuilder,
<% end %>
defaultQuery: '<%= query_string %>',
defaultQuery: '<%= sanitize(query_string) %>',
defaultVariables: '<%= variables_string %>',
defaultHeaders: <%= default_headers %>
});
Expand Down

0 comments on commit 050aac3

Please sign in to comment.