-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat: Add configurable validation security rules #1244
Merged
klausi
merged 5 commits into
drupal-graphql:8.x-4.x
from
akhomy:feature/server-security-configs-and-validation-rules
Oct 7, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8934da3
feat: Add configurable validation security rules:
akhomy 35da264
Implements PR CRs.
akhomy a30121b
Fix the server form to use a config property instead of the getter. F…
akhomy 41ac0fa
Revert back ServerForm to use ServerInterface.
akhomy 01a510d
Refactor to use variables instead of direct config call.
akhomy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ | |
use GraphQL\Server\Helper; | ||
use GraphQL\Type\Definition\ResolveInfo; | ||
use GraphQL\Validator\DocumentValidator; | ||
use GraphQL\Validator\Rules\DisableIntrospection; | ||
use GraphQL\Validator\Rules\QueryComplexity; | ||
use GraphQL\Validator\Rules\QueryDepth; | ||
|
||
/** | ||
* The main GraphQL configuration and request entry point. | ||
|
@@ -59,7 +62,10 @@ | |
* "endpoint", | ||
* "debug_flag", | ||
* "caching", | ||
* "batching" | ||
* "batching", | ||
* "disable_introspection", | ||
* "query_depth", | ||
* "query_complexity" | ||
* }, | ||
* links = { | ||
* "collection" = "/admin/config/graphql/servers", | ||
|
@@ -123,6 +129,27 @@ class Server extends ConfigEntityBase implements ServerInterface { | |
*/ | ||
public $batching = TRUE; | ||
|
||
/** | ||
* Whether to disable query introspection. | ||
* | ||
* @var bool | ||
*/ | ||
public $disable_introspection = FALSE; | ||
|
||
/** | ||
* The query complexity. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be similar to the form description like "The maximum allowed query complexity, NULL means unlimited." |
||
* | ||
* @var int|null | ||
*/ | ||
public $query_complexity = NULL; | ||
|
||
/** | ||
* The query depth. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
* | ||
* @var int|null | ||
*/ | ||
public $query_depth = NULL; | ||
|
||
/** | ||
* The server's endpoint. | ||
* | ||
|
@@ -137,7 +164,6 @@ class Server extends ConfigEntityBase implements ServerInterface { | |
*/ | ||
public $persisted_queries_settings = []; | ||
|
||
|
||
/** | ||
* Persisted query plugin instances available on this server. | ||
* | ||
|
@@ -498,10 +524,90 @@ protected function getValidationRules() { | |
return []; | ||
} | ||
|
||
return array_values(DocumentValidator::defaultRules()); | ||
$rules = array_values(DocumentValidator::defaultRules()); | ||
if ($this->getDisableIntrospection()) { | ||
$rules[] = new DisableIntrospection(); | ||
} | ||
if ($this->getQueryDepth()) { | ||
$rules[] = new QueryDepth($this->getQueryDepth()); | ||
} | ||
if ($this->getQueryComplexity()) { | ||
$rules[] = new QueryComplexity($this->getQueryComplexity()); | ||
} | ||
|
||
return $rules; | ||
}; | ||
} | ||
|
||
/** | ||
* Gets disable introspection config. | ||
* | ||
* @return bool | ||
* The disable introspection config, FALSE otherwise. | ||
*/ | ||
public function getDisableIntrospection(): bool { | ||
return (bool) $this->disable_introspection; | ||
} | ||
|
||
/** | ||
* Sets disable introspection config. | ||
* | ||
* @param bool $introspection | ||
* The value for the disable introspection config. | ||
* | ||
* @return $this | ||
*/ | ||
public function setDisableIntrospection(bool $introspection) { | ||
$this->disable_introspection = $introspection; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Gets query depth config. | ||
* | ||
* @return int|null | ||
* The query depth, NULL otherwise. | ||
*/ | ||
public function getQueryDepth(): ?int { | ||
return (int) $this->query_depth; | ||
} | ||
|
||
/** | ||
* Sets query depth config. | ||
* | ||
* @param int|null $depth | ||
* The value for the query depth config. | ||
* | ||
* @return $this | ||
*/ | ||
public function setQueryDepth(?int $depth) { | ||
$this->query_depth = $depth; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Gets query complexity config. | ||
* | ||
* @return int|null | ||
* The query complexity, NULL otherwise. | ||
*/ | ||
public function getQueryComplexity(): ?int { | ||
return (int) $this->query_complexity; | ||
} | ||
|
||
/** | ||
* Sets query complexity config. | ||
* | ||
* @param int|null $complexity | ||
* The value for the query complexity config. | ||
* | ||
* @return $this | ||
*/ | ||
public function setQueryComplexity(?int $complexity) { | ||
$this->query_complexity = $complexity; | ||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.