marcin

marcin

Hi!
How can I disable introspection in Absinthe/GraphQL?
I would like the GraphQL API to respond only to defined queries and mutations, but not allow client to list schema and types, because of security reasons (Wheter it makes sense or is security through obscurity is another issue, the requirement is not my idea).

I understand that for introspection, also GraphQL is used on fields __schema and __type.
It seems that I should be able to filter them with middleware (return :error??), but I am not sure how to add a middleware a top-level / built in queries like these.

Perhaps there is a different approach to achieve this?

Showing Posts 1 to 8

slouchpie

slouchpie

I also would like to achieve this.

I cannot make Absinthe do document validation after authentication.

fuelen

fuelen

We resolved this by middleware on a Plug level. If parameter query contains "__schema" on production servers then we reply with 403.
About 6 months ago I’ve asked this question in Slack and I saved the discussion :slight_smile:

shanesveller [6:27 PM]
now that you have the “how” it might be a good time to talk about the “why”, and how a lot of folks feel that it is counterproductive to deny introspection requests
dpehrson [6:27 PM]
I’ve yet to understand why so many people want to hide their introspection.
shanesveller [6:27 PM]
particularly if it is part of an effort to improve security
dpehrson [6:27 PM]
But it seems pretty popular.
[6:28 PM] If you’re trying to hide the API, it seems like you should just put it behind some sort of secondary auth.
[6:28 PM] Like one credential just to access the endpoint, and separate credentials for client auth.
Today
aspett [12:35 AM]
Plenty of companies do not publish documentation for their APIs and endpoints, or at least put it behind their authentication - without relying on this for security. I don’t see why GraphQL should be any different.
shanesveller [12:37 AM]
documentation is an overlapping but separate idea from introspection, though - a lot of client libs rely on the latter for codegen or at runtime, and some of those latter can’t be satisfied by a local dev environment
aspett [12:39 AM]
So? If someone wants to totally hide introspection, then that’s the tradeoff they make.
shanesveller [12:39 AM]
feels like missing the point a bit. ¯_(ツ)_/¯
[12:39 AM] not that you are, but that someone who desires to ignore that aspect is
aspett [12:40 AM]
I hope that most people are actually asking because they want to put it behind auth, rather than totally turning it off - we might consider doing that for our graphs.
benwilson512 [12:42 AM]
people are asking to have it pruned from the schema entirely
aspett [12:43 AM]
:man-shrugging: Oh well. That’s weird, but we should be explaining the reasoning and tradeoff rather than so harshly telling people they’re wrong which I’ve seen in past
benwilson512 [1:13 AM]
@aspett I think the issue is that introspection is built into the spec
[1:13 AM] it is, as far as I can tell, not considered optional
dpehrson [1:39 AM]
My feeling is that they are reaching for the wrong solution to something that likely isn’t actually a problem.
[1:39 AM] But, at the end of the day, everyone gets to chart their own course.
aspett [1:44 AM]
There are plenty of people doing it on other frameworks quite easily, so despite introspection being in the spec and disabling it probably being the wrong solution, it seems not uncommon to do so. Again, I agree with you both :smile: but people are gonna do it anyway, so it’s best we try educate rather than block.
benwilson512 [2:01 AM]
@aspett worth noting that Absinthe’s stance was never to block people, it just wasn’t really possible to do anything about it until recently (edited)
[2:01 AM] Absinthe 1.5 allows people to, amongst other things, edit the built in types
[2:02 AM] and so now I’m happy to educate and discuss, but previously there wasn’t a ton that could be done
aspett [2:02 AM]
:+1: Sorry, I mean in terms of communication
benwilson512 [2:02 AM]
yup. I think we’re on the same page at this point

fuelen [5:27 PM]
we use absinthe for private api, developers don’t work on production servers during development, so they can grab schema from other servers and codegen is not an issue. Infosec said to hide graphiql and ability to inspect schema using other clients and I’m looking for easy way to do this. That’s all
aspett
:man-shrugging: Oh well. That’s weird, but we should be explaining the reasoning and tradeoff rather than so harshly telling people they’re wrong which I’ve seen in past
dpehrson [5:28 PM]
As a person who cares about infosec greatly, that still makes no sense to me.
[5:28 PM] ¯_(ツ)_/¯
[5:29 PM] It’s not wrong, it’s just….odd.
[5:31 PM] From pure game theory, any information leak is technically bad, but practically, if exposing the types/fields of an API schema is a security risk, there seem to be much bigger problems at play. (edited)
[5:31 PM] At that point, the endpoint should be fully protected from unrecognized clients.

marcin

marcin OP

We resolved this by middleware on a Plug level. If parameter query contains “__schema” on production servers then we reply with 403.

@fuelen so you literally check for substring __schema in query, or did you do some parsing? If I post a comment about “__schema” in a legitimate addComment() mutation, will this also return 403?

fuelen

fuelen

Yes, just String.contains?(query, "__schema")

Yes and no.
Yes if parameters are inlined into query. No if parameters are passed separately.

hubertlepicki

hubertlepicki

Was that Google Review team who strongly suggested you disable introspection? :wink: I am having the same issue, quite honestly I don’t understand why they want it either.

marcin

marcin OP

No, that was a penetration testing company that reviewed our app. We needed this because we are providing service for a public institution.
Overall they had a lot of good comments/tips!

hubertlepicki

hubertlepicki

I wonder if that wasn’t the same company. Over all they were very good (surprising!) but this one requirement was kinda bummer.

Ahmad

Ahmad

I went with a similar approach to @fuelen to disable introspection completely or based on some context (e.g an authorized client, codegen tool, etc), this is a simple solution using an Absinthe plugin: Disable GraphQL schema introspection in Elixir Absinthe · GitHub

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews