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

Fix missing isRouted and access check #1305

Merged
merged 6 commits into from
Sep 23, 2022

Conversation

dbosen
Copy link
Contributor

@dbosen dbosen commented Sep 13, 2022

When redirect paths are resolved with the route_load data producer, the isRouted() and access() checks are not validated.
This leads to problems, when route_loud is called for a redirect to an external url. They should not resolve to anything.

Fixes #1306

Comment on lines 98 to 100
if ($this->redirectRepository && $redirect = $this->redirectRepository->findMatchingRedirect($path, [])) {
/** @var \Drupal\redirect\Entity\Redirect|null $redirect */
$redirect = $this->redirectRepository->findMatchingRedirect($path, []);
if ($redirect) {
return $redirect->getRedirectUrl();
}
$url = $redirect->getRedirectUrl();
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks the type annotation on line 99. The @var annotation is not needed for getRedirectUrl.

Is it possible to take the $redirect = out of the if statement for legibility?

I've opened https://www.drupal.org/project/redirect/issues/3309603 to handle the return type annotation that's incorrect for findMatchingRedirect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can take out $redirect = but that gets otherwise ugly. Would you prefer something like this?

    if ($this->redirectRepository) {
      $redirect = $this->redirectRepository->findMatchingRedirect($path, []);
      if ($redirect){
        $url = $redirect->getRedirectUrl();
      }
    }

    if(empty($url)) {
      $url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);
    }

    if ($url && $url->isRouted() && $url->access()) {
      return $url;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe something along the lines of this is better

    if ($this->redirectRepository) {
      $redirect = $this->redirectRepository->findMatchingRedirect($path, []);
    }
    if (!empty($redirect)){
      $url = $redirect->getRedirectUrl();
    }
    else {
      $url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a ternary may be okay, I also tend to avoid empty checks if possible.

<?php

$redirect = $this->redirectRepository ? $this->redirectRepository->findMatchingRedirect($path, []) : NULL;
if ($redirect !== NULL) {
  $url = $redirect->getRedirectUrl();
}
else {
  $url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Kingdutch Kingdutch merged commit 31c4753 into drupal-graphql:8.x-4.x Sep 23, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[4.x] Missing isRouted and access check in route_load data producer
2 participants