Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinenar committed Sep 19, 2024
1 parent e8a4784 commit 62928fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For example:
}
```

Security Impact of Alias Overloading:
Security Impact of Circular References in GraphQL:

- **Denial of Service**: By sending a large query with too many nested references, an attacker can overwhelm the server, causing it to slow down or crash.
- **Resource Exhaustion**: The server may run out of memory or CPU resources while processing the query, leading to performance degradation or service unavailability.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ To mitigate the risk of circular references in GraphQL, you can follow these rec
1. **Depth Limiting**:
Implement a middleware to check the depth of the query, and raise an error if it exceeds the limit.
Example:
=== "Python"
```python
=== "python"
```python
class DepthAnalysisMiddleware:
def resolve(self, next, root, info, **args):
if info.operation.selection_set:
Expand All @@ -18,25 +18,26 @@ Example:
if field.selection_set:
return 1 + max(self._get_depth(f) for f in field.selection_set.selections)
return 1
```
```


2. **Circular Reference Detection**:
Redesign the schema to avoid circular references.
Example of Circular Reference:
=== "Python"
```python
=== "python"
```python
class User(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()
friends = graphene.List(lambda: User)

def resolve_friends(self, info):
return [User(id=1, name='Alice'), User(id=2, name='Bob')]
```
```

Example of redesigned Schema:
=== "Python"
```python
=== "python"
```python
class FriendProfile(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()
Expand All @@ -48,24 +49,25 @@ Example of redesigned Schema:

def resolve_friends(self, info):
return [FriendProfile(id=1, name='Alice'), FriendProfile(id=2, name='Bob')]
```
```


=== "JavaScript"
```javascript
const FriendProfile = new GraphQLObjectType({
name: 'FriendProfile',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString }
}
});

const User = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString },
friends: { type: new GraphQLList(FriendProfile) }
}
});
```
```javascript
const FriendProfile = new GraphQLObjectType({
name: 'FriendProfile',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString }
}
});
const User = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString },
friends: { type: new GraphQLList(FriendProfile) }
}
});
```

0 comments on commit 62928fe

Please sign in to comment.