Prevent exposing GraphQL API Schema Structure to unauthorized users.
defmodule MyAppWeb.Schema do
use Absinthe.Schema
query do
# Queries defined here
end
mutation do
# Mutations defined here
end
end
# Endpoint configuration
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
socket "/graphiql", Absinthe.Plug.GraphiQL, schema: MyAppWeb.Schema
end
This code is insecure because it enables introspection queries, allowing anyone to retrieve the entire GraphQL API Schema Structure. This can lead to information leakage, helping an attacker to craft more targeted attacks.
defmodule MyAppWeb.Schema do
use Absinthe.Schema
query do
# Queries defined here
end
mutation do
# Mutations defined here
end
end
# Endpoint configuration
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
socket "/graphiql", Absinthe.Plug.GraphiQL, schema: MyAppWeb.Schema, interface: Mix.env() != :prod
end
This code is secure because it disables introspection queries in the production environment. The introspection queries are only available in non-production environments, reducing the risk of information leakage.