graphql security - owasp.org€¦ · /graphql this is the default. it is a convention that has been...

31
GraphQL Security OWASP YVR 2020

Upload: others

Post on 09-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

GraphQL SecurityOWASP YVR 2020

Page 2: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Hello!

I’m Don BurksTechnical Lead @ Sphere

You can find me at @don_burks

2

Page 3: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

SomeAssumptions

You understand what GraphQL is… and isn’t.

3

There is an implementation of GraphQL in your present or near future

AppSec is something you know is important.

Page 4: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

“Just because

it is new, that does not

mean that it is secure.

4

Page 5: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

“Ask the MongoDB

community.

5https://zdnet3.cbsistatic.com/hub/i/r/2018/02/16/8abdb3e1-47bc-446e-9871-c4e11a46f680/resize/470xauto/2ea638bf5532abe5081dabb0fbecbc2d/mongo-db-logo.png

Page 6: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Tips for securing your GraphQL

◈ Route change

◈ Introspection

◈ Authentication

◈ Depth / Complexity

◈ Schema generation6

Page 7: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Route ChangeMany things we do as developers are

conventions, not requirements

7

Page 8: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

/graphqlThis is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations.

This makes it a target.

/fluffybunnyNot a standardly enumerated route. Works just as well as the default. Neither the client, nor the server, is going to care what route the request comes in on, as long as it is a well-formed request.

8

Page 9: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

9https://vignette.wikia.nocookie.net/hoodwinked/images/3/35/Hoodwinked_boingo_evil_glare.png

Trustthe bunny

Page 10: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

ALSO!

Disable /graphiql

Yes, in all env’s.

Tools such as graphql-ide or Insomniaare better.

10

Page 11: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

IntrospectionGreat when you’re alone. Not so great when you’re standing in front of 7 billion people.

11

Page 12: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Disable introspection in your testing and production environments.

◈ Apollo and fastify-gql now do this by default (in prod)

◈ Test for introspection leakiness in your testing env

12

Page 13: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

AuthenticationThis tends to be a big mistake I see in new

GraphQL implementations.

13

Page 14: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Layers of Authentication

JWTJSON Web Tokens passed in the Authorization header can be checked at the context level with each query.

Just like an API.

ACLAccess Control means that admin queries are restricted to admin accounts. It means resource ownership and / or edit privileges are checked.

EdgesDon’t forget to add auth and / or ACL to the resolvers that facilitate your edges. A malicious attacker could easily exploit this to access leaky data.

14

Page 15: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

type User {

id: ID

email: String

username: String

admin: Boolean

createdAt: String

updatedAt: String

lastLogin: String

}

type Post {

id: ID

title: String

body: String

author: User

createdAt: String

updatedAt: String

}

15

Page 16: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

16

Post: {author: (post) => {

return someDB.select(“*”)..from(“users”).where(“id”, post.author_id).limit(1);

})}

Page 17: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

17

Post: {author: (post, args, context) => {

if (context.user.admin || context.user.id === post.author_id) {

return someDB.select(“*”)..from(“users”).where(“id”, post.author_id).limit(1);

}})

}

Page 18: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Depth / ComplexityEasier than you think.

More important than you realize.

18

Page 19: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

DepthIs the number of edges your query is trying to access.

Too much depth can DDOS your server due to overloading your data store.

Different types of complicated queries

ComplexitySome queries may have extreme complexity to them, and should be evaluated accordingly. This involves queries doing heavy joins, aggregations, or retrieving data from external APIs.

19

Page 20: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

query {users {

posts {user {

posts {user {

posts {user {

posts {id

}}

}}

}}

}}

}20

Page 21: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

query {users(first: 50) {

posts(last: 10) {idtitlebody

}}

}

21

50 Nodes+ 50 * 10 Nodes

= 550 Nodes

Page 22: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

query {users(first: 5000) {

posts(last: 100) {idtitlebody

}}

}

22

5000 Nodes+ 5000 * 100 Nodes

= 505,000 Nodes!!!

Page 23: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

5If your query is deeper than this, I’m not

sure that query depth is your biggest issue.

23

Page 24: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Schema GenerationHey, this is so cool!

It hacked my site for me!

24

Page 25: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

If it seems magical,

It is probably

dangerous

25https://live.staticflickr.com/3793/10178307913_91956693a1_b.jpg

Page 26: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Generators

One of the more dangerous approaches to implementing GraphQL by using a tool to auto-generate the SDL.◈ Translates all SQL table fields into SDL

schema fields◈ Auto-creates queries and mutations to

accomplish CRUD functions

26

Page 27: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

27

https://img.webmd.com/dtmcms/live/webmd/consumer_assets/site_images/article_thumbnails/recipes/chocolate_pudding_sprinkle_cones_recipe/650x350_chocolate_pudding_sprinkle_cones_recipe.jpg

REST with SPRINKLES!!

Page 28: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Design your SDL Schema, don’t generate it!

SDL

Mutations

Queries

28

Page 29: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Data youHave

Data thatClient Needs

You get the opportunity to CRAFT your schema

GraphQL

29

Page 30: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Summary

30

◈ Send your authenticated query...

◈ To a back-end with a thoughtful schema...

◈ Where the depth and complexity are evaluated...

◈ And the endpoint is non-standard...

◈ Before you start thinking that you’re secure.

Page 31: GraphQL Security - owasp.org€¦ · /graphql This is the default. It is a convention that has been adopted as the go-to endpoint for all GraphQL implementations. This makes it a

Thanks!

Any questions?

You can find me at:@don_burks · donburks.com https://sphere.guide

31