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

feat: Add configurable validation security rules #1244

Merged
merged 5 commits into from
Oct 7, 2021
Merged

feat: Add configurable validation security rules #1244

merged 5 commits into from
Oct 7, 2021

Conversation

akhomy
Copy link
Contributor

@akhomy akhomy commented Oct 1, 2021

This is just simplified version of the #1239 according to the discussion - #1239 (comment)

Scope:

  • Provides new config values and getters, setters for them.

  • Add configurable validation security rules:

    • Disable introspection
    • Query depth
    • Query complexity

- Disable introspection
- Query depth
- Query complexity
Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the approach looks good! Type hints are missing for the new methods and I think we should not change the interface as 4.0 was already released (would need 5.x).

Once that is cleaned up I think we can merge.

* @return bool
* The disable introspection config, FALSE otherwise.
*/
public function getDisableIntrospection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not change the interface at this point because graphql 4.0 has already been released.

Can we only do the changes on the Server class?

type: integer
label: 'Max query depth'
query_complexity:
type: number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does number exist? should also be integer?

/**
* {@inheritdoc}
*/
public function getDisableIntrospection() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add return type hints to the helpers, bool here

/**
* {@inheritdoc}
*/
public function setDisableIntrospection($introspection) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool param type

@akhomy akhomy requested a review from klausi October 5, 2021 15:23
@akhomy
Copy link
Contributor Author

akhomy commented Oct 5, 2021

@klausi , implemented CRs.

Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - sorry I overlooked a couple of details, one more round?

*
* @return $this
*/
public function setQueryDepth(int $depth) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type hint should be ?int so that you can disable this setting, right?

*
* @return $this
*/
public function setQueryComplexity(int $complexity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

$rules[DisableIntrospection::class] = new DisableIntrospection();
}
if ($this->getQueryDepth()) {
$rules[QueryDepth::class] = new QueryDepth($this->query_depth);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, we forgot to add the new properties to the class and document them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@klausi , my bad, I forgot to use the appropriate getter. Added it in a new commit.

$form['validation']['disable_introspection'] = [
'#title' => $this->t('Disable introspection'),
'#type' => 'checkbox',
'#default_value' => $server->getDisableIntrospection(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, should we use the new methods here? they might not exist if somebody has swapped out the entity class and does not inherit them. Maybe an edge case and we don't care, but I think we should use $server->get() to be on the safe side.

@akhomy akhomy requested a review from klausi October 6, 2021 05:21
Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, please add the class properties for consistency, then I think we should be done.

* "batching",
* "disable_introspection",
* "query_depth",
* "query_complexity"

This comment was marked as resolved.

@klausi
Copy link
Contributor

klausi commented Oct 6, 2021

Tests are failing, but does not look related to this issue.

@akhomy akhomy requested a review from klausi October 7, 2021 07:04
Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I would just improve the comments a bit, but I can do that in a follow-up commit

public $disable_introspection = FALSE;

/**
* The query complexity.
Copy link
Contributor

Choose a reason for hiding this comment

The 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."

public $query_complexity = NULL;

/**
* The query depth.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@klausi klausi merged commit 0d07207 into drupal-graphql:8.x-4.x Oct 7, 2021
chrfritsch added a commit to chrfritsch/graphql that referenced this pull request Nov 24, 2021
* 8.x-4.x:
  fix(dataproducer): Fix language definition to be single value in entity reference producers (drupal-graphql#1241)
  docs(server): Improved class property descriptions
  feat(server): Add configurable validation security rules for introspection and query complexity (drupal-graphql#1244)
  tests(buffer): Fix ArryObject usage to not depend on Zend (drupal-graphql#1247)
  test(phpstan): Add missing return type hint
  fix(file-upldoad): Validate files in the correct order
  fix(DataProducer): Fix entity reference loading by language (drupal-graphql#1232)
  tests(assertions): Implement leaked metadata detection for QueryResultAssertionTrait (drupal-graphql#1207)
  tests(github): Switch testing to Drupal core 9.2.x (drupal-graphql#1215)
  chore(voyager): yarn audit security updates (drupal-graphql#1214)
  test(phpstan): Enable PHPStan run on PHP 8.0 (drupal-graphql#1211)
  refactor(executor): Replace deprecated AST::getOperation() with AST::getOperationAST() (drupal-graphql#1210)
  fix(executor): Remove swapped errors compatibility mode
klausi pushed a commit to klausi/graphql that referenced this pull request Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants