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.

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
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
Building GraphQL APIs on top of Ethereum with The Graph
GraphQL Galaxy 2021GraphQL Galaxy 2021
48 min
Building GraphQL APIs on top of Ethereum with The Graph
WorkshopFree
Nader Dabit
Nader Dabit
The Graph is an indexing protocol for querying networks like Ethereum, IPFS, and other blockchains. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.

In this workshop you’ll learn how to build a subgraph that indexes NFT blockchain data from the Foundation smart contract. We’ll deploy the API, and learn how to perform queries to retrieve data using various types of data access patterns, implementing filters and sorting.

By the end of the workshop, you should understand how to build and deploy performant APIs to The Graph to index data from any smart contract deployed to Ethereum.

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
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
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
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
The Guild has recently released Envelop - a new, modern GraphQL Server Framework and plugin system. In this talk I’ll share a brief overview of Envelop and why you should probably upgrade your existing GraphQL server to it.
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
In this talk, we'll look at some of the modern options for building a full-stack React and GraphQL app with strong conventions and how this can be of enormous benefit to you and your team. We'll focus specifically on RedwoodJS, a full stack React framework that is often called 'Ruby on Rails for React'.
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
Though GraphQL is declarative, resolvers operate field-by-field, layer-by-layer, often resulting in unnecessary work for your business logic even when using techniques such as DataLoader. In this talk, Benjie will introduce his vision for a new general-purpose GraphQL execution strategy whose holistic approach could lead to significant efficiency and scalability gains for all GraphQL APIs.