Make BrowserShot Optional in SitemapGenerator #558
Merged
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.
Summary of the Change
This pull request proposes making BrowserShot and the Crawler functionality optional in the SitemapGenerator package. The current implementation forces these dependencies even for users who don’t require dynamic crawling, introducing security risks and compatibility challenges.
Given the recent security issue in BrowserShot, along with its PHP version requirements, and the additional unnecessary dependencies, this change aims to improve flexibility and reduce overhead for users of the package.
Why This Change is Necessary
1. Security Concern
The BrowserShot package had a security issue that was patched in version 5. However, the patched version requires PHP 8.2. Many applications, including ours, are still running on PHP 8.1, leaving them unable to use the patched version and exposed to vulnerabilities in BrowserShot v3.
2. Unnecessary Dependencies
Currently, Spatie Laravel Sitemap pulls in several dependencies that are only required for the Crawler feature. For users who generate sitemaps directly (without crawling), these dependencies add unnecessary overhead, increasing maintenance complexity and potential attack surfaces.
3. Symfony DomCrawler Note
We noticed that
symfony/dom-crawler
is explicitly required in thecomposer.json
ofspatie/laravel-sitemap
, but it appears to be unnecessary as it is already required byspatie/crawler
.👉 Reference: spatie/crawler
composer.json
4. Our Use Case
In our projects, we generate sitemaps directly from routes and database queries. We do not use the crawling functionality, yet we are forced to install these dependencies, which are never actually used in our application.
Removed Dependencies
By making BrowserShot and Crawler optional, the following packages will no longer be required:
masterminds/html5
nicmart/tree
spatie/browsershot
spatie/crawler
spatie/robots-txt
spatie/temporary-directory
symfony/dom-crawler
Benefits of This Change
Reduced Security Risk
Users who don’t require dynamic crawling won’t be exposed to potential vulnerabilities in these packages if any arise in the future.
Reduced Overhead
Removing unnecessary dependencies results in a lighter application footprint, faster builds, and less complexity.
Increased Flexibility
Users can choose to install BrowserShot and Crawler only if their use case requires it.
Proposed Change
As the SitemapGenerator class is already conditionally using BrowserShot only when the package is configured to use the Crawler, we propose to:
composer.json
file.spatie/crawler
to therequire-dev
section on thecomposer.json
file to allow testing.symfony/dom-crawler
dependency to ensure it is truly necessary inspatie/laravel-sitemap
.Closing Thoughts
We highly value the contributions of Spatie to the Laravel community. This proposed change aims to improve the Laravel Sitemap package by making it more flexible and secure while reducing unnecessary dependencies for users who don’t need the Crawler functionality.
We appreciate your consideration of this pull request and look forward to any feedback. Thank you for your continued efforts to enhance the Laravel ecosystem!