-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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(gatsby): handle encoded URLs in SSR #39157
Open
emmron
wants to merge
9
commits into
gatsbyjs:master
Choose a base branch
from
emmron:fix/39010-ssr-encoded-urls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+196
−335
Conversation
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
gatsbot
bot
added
the
status: triage needed
Issue or pull request that need to be triaged and assigned to a reviewer
label
Nov 7, 2024
- Replace single quotes with backticks for consistency - Add explicit express.RequestHandler return type - Fix prettier formatting for template literals - Improve code formatting and readability
emmron
force-pushed
the
fix/39010-ssr-encoded-urls
branch
2 times, most recently
from
November 7, 2024 12:33
186553b
to
878b976
Compare
fix(ssr): Improve URL sanitization and routing in serve.js for SSR - Enhance `sanitizeUrl` function to comprehensively handle nested encodings, control characters, query parameters, hash fragments, and path traversal. - Add iterative decoding in `sanitizeUrl` to support URLs with multiple encoding layers. - Normalize URLs by stripping extraneous characters, collapsing redundant slashes, ensuring a leading slash, and conditionally removing trailing slashes. - Implement `createMatchPathMiddleware` with modularized helpers: - `sanitizeUrl`: Cleans and normalizes URL paths. - `findMatchPath`: Safely finds a matching path with error handling. - `logMatch`: Logs match details if logging is enabled. - `handleError`: Centralized error handler for consistent logging and responses. - Add caching for URL matches to improve performance. - Add informative logs for matched paths, request durations, and errors. - Ensure compatibility with various URL structures and improve security against path traversal vulnerabilities. - Improve maintainability by breaking down the code into modular, reusable functions. This commit addresses [Issue gatsbyjs#39010](gatsbyjs#39010) and enhances SSR handling for encoded URLs, improving both performance and robustness in the `serve.js` middleware.
billyb000b
approved these changes
Nov 7, 2024
billyb000b
approved these changes
Nov 7, 2024
emmron
force-pushed
the
fix/39010-ssr-encoded-urls
branch
from
November 7, 2024 13:28
878b976
to
a0aef26
Compare
Refactor the serve.ts file to improve URL handling and add support for SSL. This includes importing the 'http' and 'https' modules, creating a server based on the SSL configuration, and updating the startListening function to use the appropriate protocol. This change enhances the URL sanitization and routing in serve.js for SSR, and also handles encoded URLs in SSR for Gatsby. The code changes also fix linting issues and improve URL logging and error handling. The commit message follows the established convention of using a verb in the imperative mood, specifying the area of the code being modified, and providing a concise summary of the changes made. Signed-off-by: Emmett Hoolahan <[email protected]>
…n/gatsby-issue-25207-fix into fix/39010-ssr-encoded-urls
billyb000b
approved these changes
Nov 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
status: triage needed
Issue or pull request that need to be triaged and assigned to a reviewer
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.
Fixes #39010
Problem:
Solution:
Test Plan: