Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New CS: GraphQL #434

Merged
merged 29 commits into from
Oct 30, 2020
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca64aac
Merge pull request #1 from OWASP/master
bigshebang Jun 17, 2020
c32fd1e
feat: add first draft of GraphQL Cheat Sheet
bigshebang Jun 18, 2020
904b814
chore: fix formatting to match guidelines
bigshebang Jun 18, 2020
d67346a
chore: md clean up
ThunderSon Jun 20, 2020
bf8ccf8
chore: header tweaks
ThunderSon Jun 20, 2020
5d0c975
revision 1 based on feedback
bigshebang Aug 16, 2020
6b41373
Add ORM/ORD feedback from PauloASilva
bigshebang Aug 19, 2020
b6fc880
Add tool vs API feedback from PauloASilva
bigshebang Aug 19, 2020
0166339
Adding DoS change from PauloASilva
bigshebang Aug 23, 2020
b025b22
Another DoS change from PauloASilva
bigshebang Aug 23, 2020
0547d00
Add missing parenthesis to link
bigshebang Aug 23, 2020
045a21f
adding real content for OS DoS placeholders
bigshebang Sep 2, 2020
0b3844a
added an example attack query for amount limiting
bigshebang Sep 2, 2020
506a287
touched up the DoS section a bit
bigshebang Sep 2, 2020
c483d37
rearranging IDOR to be under the access control section
bigshebang Oct 5, 2020
c734132
Important wording fix from PauloASilva
bigshebang Oct 6, 2020
934c422
IDOR clarification from PauloASilva
bigshebang Oct 6, 2020
c86ef61
move content to new insecure defaults section
bigshebang Oct 8, 2020
5fa8cb1
Merge branch 'new-CS_421' of github.com:bigshebang/CheatSheetSeries i…
bigshebang Oct 8, 2020
2613cf6
add content for batch attacks; clean up other loose ends
bigshebang Oct 12, 2020
d43e786
Add batching attack mitigation for DOS attacks, from Paulo
bigshebang Oct 14, 2020
5afd00a
add content changes/additions per Paulo's suggestions
bigshebang Oct 14, 2020
d891cc6
Fix wording and add proper input validation CS link
bigshebang Oct 23, 2020
4092bbe
Letting ThunderSon fix up some javascript
bigshebang Oct 23, 2020
67d47bb
changes based on ThunderSon's feedback
bigshebang Oct 23, 2020
2f8b358
Update cheatsheets_draft/GraphQL_Cheat_Sheet.md
bigshebang Oct 23, 2020
5d865f5
fixing remaining CS links
bigshebang Oct 23, 2020
3f960b1
changing WSTG from latest to stable
bigshebang Oct 23, 2020
dc5486a
Fixing javascript code snippet
bigshebang Oct 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions cheatsheets_draft/GraphQL_Cheat_Sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Below are some quick high-level ideas to keep in mind when building a secure API
- [OS Command injection](https://owasp.org/www-community/attacks/Command_Injection)
- [SSRF](https://portswigger.net/web-security/ssrf) and [CRLF](https://owasp.org/www-community/vulnerabilities/CRLF_Injection) [injection](https://www.acunetix.com/websitesecurity/crlf-injection/)/[Request](https://portswigger.net/web-security/request-smuggling) [Smuggling](https://www.pentestpartners.com/security-blog/http-request-smuggling-a-how-to/)
- [DoS](https://owasp.org/www-community/attacks/Denial_of_Service) ([Denial of Service](https://www.cloudflare.com/learning/ddos/glossary/denial-of-service/))
- [IDOR](https://portswigger.net/web-security/access-control/idor)
- Broken authorization: either [improper](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md) or [excessive](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa3-excessive-data-exposure.md) access
- Broken authorization: either [improper](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md) or [excessive](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa3-excessive-data-exposure.md) access, including [IDOR](https://portswigger.net/web-security/access-control/idor)

## Best Practices and Recommendations

Expand Down Expand Up @@ -191,12 +190,21 @@ Not properly limiting the amount of resources your API can use (e.g. CPU or memo
To ensure that a GraphQL API has proper access control, do the following:

- Always validate that the requester is authorized to view or mutate/modify the data they are requesting. This can be done with [RBAC](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Access_Control_Cheat_Sheet.md#role-based-access-control-rbac) or other access control mechanisms.
- This will prevent [IDOR](https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html) issues, including both [BOLA](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md) and [BFLA](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md).
- Enforce authorization checks on both edges and nodes (see example [bug report](https://hackerone.com/reports/489146) where nodes did not have authorization checks but edges did).
- Use [Interfaces](https://graphql.org/learn/schema/#interfaces) and [Unions](https://graphql.org/learn/schema/#union-types) to create structured, hierarchical data types which can be used to return more or fewer object properties, according to requester permissions.
- Query and Mutation [Resolvers](https://graphql.org/learn/execution/#root-fields-resolvers) can be used to perform access control validation, possibly using some RBAC middleware.
- [Disable introspection queries](https://lab.wallarm.com/why-and-how-to-disable-introspection-query-for-graphql-apis/) system-wide in any production or publicly accessible environments.
- Disable [GraphiQL](https://github.com/graphql/graphiql) and other similar schema exploration tools in production or publicly accessible environments.

#### General Data Access

It's commonplace for GraphQL requests to include one or more direct IDs of objects in order to fetch or modify them. For example, a request for a certain picture may include the ID that is actually the primary key in the database for that picture. As with any request, the server must verify that the caller has access to the object they are requesting. But sometimes developers make the mistake of assuming that possession of the object's ID means the caller should have access. Failure to verify the requester's access in this case is called [Broken Object Level Authentication](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md), which is a subset of a weakness called [IDOR](https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html).
bigshebang marked this conversation as resolved.
Show resolved Hide resolved

> New section from nikitastupin. Not something I can personally verify with my limited GraphQL experience, so would be great if someone else can check this out.

It's possible for a GraphQL API to support access to objects using their ID even if that is not intended. Sometimes there are `node` or `nodes` or both fields in a query object, and these can be used to access objects directly by `ID`. You can check whether your schema has these fields by running this on the command line (assuming that `schema.json` contains your GraphQL schema): `cat schema.json | jq ".data.__schema.types[] | select(.name==\"Query\") | .fields[] | .name" | grep node`. You can remove these fields from the schema to disable the functionality. Or as stated above you can apply proper authorization checks to verify the caller has access to the object they are requesting.
bigshebang marked this conversation as resolved.
Show resolved Hide resolved

#### Query Access (Data Fetching)

As part of a GraphQL API there will be various data fields that can be returned. One thing to consider is if you want different levels of access around these fields. For example, you may only want certain consumers to be able to fetch certain data fields rather than allowing all consumers to be able to retrieve all available fields. This can be done by adding a check in the code to ensure that the requester should be able to read a field they are trying to fetch.
Expand Down Expand Up @@ -234,14 +242,6 @@ app.use('/graphql', graphqlHTTP({
}));
```

### IDOR Protection

In general, proper access controls will prevent any IDOR attacks since IDOR merely represents 2 separate authorization issues: [Broken Object Level Authorization](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa1-broken-object-level-authorization.md) and [Broken Function Level Authorization](https://github.com/OWASP/API-Security/blob/master/2019/en/src/0xa5-broken-function-level-authorization.md). See the [IDOR prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html) for a comprehensive rundown of preventing IDOR.

> New section from nikitastupin. Not something I can personally verify with my limited GraphQL experience, so would be great if someone else can check this out.

Sometimes there are `node` or `nodes` or both fields in a query object. They can be used to access objects directly by `ID` which often introduces authorization vulnerabilities. You can check whether your schema has these fields by running this on the command line (assuming that `schema.json` contains your GraphQL schema): `cat schema.json | jq ".data.__schema.types[] | select(.name==\"Query\") | .fields[] | .name" | grep node`. To prevent such vulnerabilities either remove these fields or apply proper authorization checks when objects accessed directly by `ID` as discussed earlier in the "Access Control" section.

## Other Resources
bigshebang marked this conversation as resolved.
Show resolved Hide resolved

### Tools
Expand Down