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

Exclude cached routes with randomly generated names #370

Merged
merged 3 commits into from Nov 21, 2020

Conversation

bakerkretzmar
Copy link
Collaborator

When you run php artisan route:cache, Laravel assigns unnamed routes a unique, randomly generated name that looks something like generated::ZRopaJJwzA27wRLa.

Ziggy should ignore these routes because they don't actually have explicit names assigned by the developer, so including them in the output will increase its size considerably and could expose information that should not be visible client-side.

To that end, this PR just filters out any route whose name starts with generated::.


I tried to actually cache the routes in a test, but Testbench doesn't support this out of the box and I kept getting very weird Opis/Closure errors. Here's what I was trying, more or less:

    // tests/TestCase.php

    protected function cacheRoutes()
    {
        $routes = app('router')->getRoutes();
        $routes->refreshNameLookups();
        $routes->refreshActionLookups();

        foreach ($routes as $route) {
            $route->prepareForSerialization();
        }

        $this->laravelVersion(7)
            ? app('router')->setCompiledRoutes($routes->compile())
            : app('router')->setRoutes($routes);
    }

@bakerkretzmar bakerkretzmar merged commit aa8a5bb into main Nov 21, 2020
@bakerkretzmar bakerkretzmar deleted the jbk/exclude-generate-routes branch November 21, 2020 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant