How to Automate Security Testing for Your GraphQL Service

Rate this content
Bookmark

We’ve all heard the buzz around pushing application security into the hands of developers, but if you’re like most companies, it has been hard to actually make this a reality. You aren’t alone – putting the culture, processes, and tooling in place to make this happen is tough – especially for sophisticated applications like those backed by GraphQL.


In this hands-on technical session, StackHawk Lead Engineer Topher Lamey will walk through how to protect your GraphQL APIs from vulnerabilities using automated security testing. Get ready to roll-up your sleeves for automated AppSec testing.

This workshop has been presented at GraphQL Galaxy 2022, check out the latest edition of this Tech Conference.

FAQ

The workshop introduced three types of automated security testing for GraphQL services: Software Composition Analysis (SCA), Static Application Security Testing (SAST), and Dynamic Application Security Testing (DAST).

SCA works by examining the dependencies of your application to identify known vulnerabilities. Tools like Dependabot are used to alert developers about these vulnerabilities in the dependencies being used.

SAST analyzes your code to identify known security issues and vulnerabilities by looking for patterns and potential problems directly in your source code. It is useful for pointing out exact lines of code where issues may exist.

Unlike SAST, DAST involves testing an actively running version of your application. It scans the live application, identifying vulnerabilities that are present in the running instance, which might not be directly linked to the source code.

For implementing SAST, tools such as CodeQL and possibly Snyk were utilized. DAST was implemented using StackHawk, which integrates with various CI/CD pipelines and runs tests on the live application.

Security testing is integrated into the CI/CD pipeline by adding specific actions or steps that run security tests every time code is committed. This includes setting up GitHub actions for automated builds, and integrating tools like CodeQL and StackHawk for continuous security testing.

To set up security testing, you typically fork a vulnerable example repository into your own GitHub account, modify it by adding security testing tools in the CI/CD configuration, and then commit changes to test the setup.

Finding bugs early in the development cycle reduces the cost and time needed for fixes, minimizes disruptions, and improves the overall security and quality of the application before it reaches production.

StackHawk is used for dynamic application security testing. It scans live applications to identify real-time vulnerabilities and integrates with CI/CD pipelines to automate the testing process.

Integrating with tools like Snyk enhances security testing by correlating static analysis findings with dynamic testing results, providing a more comprehensive view of potential vulnerabilities in both the source code and the running application.

Topher Lamey
Topher Lamey
76 min
07 Dec, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

The workshop focuses on automating security testing for a GraphQL service using software composition analysis, static application security testing (SAST), and dynamic application security testing (DAST). GitHub Actions is used to set up an automated workflow, including dependency scanning with Dependabot and code scanning with CodeQL. StackHawk is implemented for dynamic app scanning, and integration with Snyk and CodeQL is demonstrated. The workshop emphasizes the importance of early bug detection and provides insights into vulnerabilities in the GraphQL application.

1. Introduction to Workshop and Speaker

Short description:

Welcome to the workshop on automating security testing for a GraphQL service. We'll be forking an example repo, modifying it, and adding security testing in the CICD pipeline. I'm Topher, a Lead Software Engineer at Stackhawk, and I'll be guiding you through the workshop.

Welcome, everybody. Thank you for your time. We really appreciate it.

In this workshop, we're going to be going through automating security testing for a GraphQL service. So what we're going to do is take a vulnerable example GraphQL service, and we're going to put some security testing in the CICD pipeline for that repo. And that really gives us some nice coverage around the code and the application which helps us find bugs earlier, because really, that's the point. You want to find those bugs as soon as possible.

So we're going to be, we'll go through the agenda, but just at a high level, we're going to be forking an example repo, modifying that repo, adding in some GitHub actions to do some testing. We're going to be hooking up CodeQL from GitHub and Stackhawk scanning. So we'll be able to really get some good testing into, around this application and surface some of those vulnerabilities.

A little bit about me before we get into things. My name is Topher. I'm a Lead Software Engineer here at Stackhawk. I've been here since, almost since the very beginning of the company, I was the second engineer hired after a principal architect. When I started, there was no source code at all. So I've been involved kind of building everything for Stackhawk from the ground up, process, code, architecture, all that kind of stuff. I'm in Colorado. I've been in the startup world for quite a long time, since the mid 90's, was my first one. I started out in the Bay Area. Probably, the one that you might have heard is I worked, I was at Netscape early on, way back in the day. I was there when they were inventing JavaScript and SSL, or TLS as it's called now, and all sorts of stuff. That was super fun. I've got some kids, love to ride my bike. And my main hobby is play music. So I try and get out and play as much as possible. And Nicole is my co-host, by the way, she's the one who's going to be helping out with the Discord and everything.

2. Overview of Security Testing

Short description:

In this workshop, we'll be implementing three types of automated security testing for a GraphQL service: software composition analysis, static application security testing (SAST), and dynamic application security testing (DAST). We'll enable software composition analysis to check for vulnerabilities in dependencies. SAST analyzes code for known patterns, while DAST scans the live running application. We'll be using StackHawk, an easy-to-use tool built around ZAP, an open source scanner. Early bug detection in the development cycle is crucial, and StackHawk simplifies the process by aggregating and providing historical information on test results.

So before we get into the workflow steps, I wanted to kind of give a little bit of overview of the security stuff that we were talking about and why it's important. So in this workshop, we're going to be doing, implementing three different types of automated security testing for this GraphQL service.

And so the three major types, the way we think about it, the way I think about it is we have this first one here called software composition analysis. If you use GitHub, you've probably seen Dependabot give you some notices, or at least they've asked you to enable Dependabot. And kind of what this does is it just looks at your dependencies and says, hey, are there vulnerabilities in these dependencies and then tells you about it. It's useful in that, you know, if you're using something, the big recent one was the log for shell one. If you're using that library or if it's a downstream dependency or something like that, this will let you know. The other, kind of the downsides are it's not looking at things in your code, in your specific logic for your code or in your application. It's really just looking at known vulnerabilities and dependencies. But it is very fast and it's really cheap and easy to implement. So it's a good one, software composition analysis. It's good to know. It's good to have. We're gonna be enabling that as part of the first step that we're gonna go through.

And then the second one is static application security testing. I also call it SAST. So if you hear me say SAST, that's what I'm talking about. So some big vendors here are Snyk, CodeQL, that's what that top icon is. And what this does is it looks at your code. So it analyzes your code and it's not quite a compiler, but it looks for things in your code. It's got a parser and it tries to identify known patterns in your source code and alerts it to them. It's really nice because it has a specific line of code that it will point out and it's really helpful. The downside is that it's not always right. Like it's just a guess, it's a well-educated guess, but it's still at the end of the day. It's just a guess. But we're gonna be implementing that as well. So we're gonna turn on CodeQL as part of this demo and then maybe if we have time, sneak as well, because we just launched that.

So we've got the third one then is the Dynamic Application Security Testing or DAST. So what this does, this is different in that it actually stands up an instance of your application and then runs a scanner against the live running application. And so it's very useful because when it finds a problem, it's actually a problem in the running application. One of the things that's difficult, though, is that it doesn't point out the line of code like the SAS does. But you know that this vulnerability is here and you can go then go trace it down and try and figure out what's going on. So DAST tools, we've got StackHawks, ZAP and BurpSuite. Today we're gonna be going to be implementing StackHawk, which I work for and it's a great product. And yeah, so those are the three different types of security products that we're gonna be implementing on this sample application today. We're gonna be putting them in the build pipeline. So on every commit that goes against any branch, just the way we're gonna set it up, it will run these tests and then we will know if that commit caused a regression. And so as kind of conventional wisdom at this point, but it's worth pointing out that the earlier you find a bug in the dev cycle, security or otherwise, the faster and cheaper and quicker and better is to fix it because you know that whatever I just did, whatever I just checked in changed something and caused something, this alert to trigger, the security issue to be found. So those are the three different types. And that's kind of why we're doing it. Stackhawk, we think we do this really well. So we are built around ZAP, which is a open source scanner. We build it and package it specifically for CI CD. So we make it real easy to use in GitHub Actions, Jenkins, code builds, all kinds of different build systems. We make it easy to run in CI CD and easy to understand what's going on. So we take the results just at a high level. What happens is our scanner runs and pushes the results to our platform where they get aggregated and there's historical information and you can kind of go back in time and see if things changed. Kind of, you can do reports, all kinds of functionality and features around the DAST test that get run. So basically we want it to be fast and easy to use and understand because there's some security tools out there like, hey there's a problem and then you really don't know. It takes a bit of detective work to figure out what's going on.

Watch more workshops on topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.