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

16348 http url query contains semicolon which is no longer a supported separator 1 #967

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dqunbp
Copy link
Contributor

@dqunbp dqunbp commented Jan 29, 2025

https://kontur.fibery.io/Tasks/Task/http-URL-query-contains-semicolon,-which-is-no-longer-a-supported-separator-16348

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL query handling to resolve potential parsing issues with semicolons in request URLs.

Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request introduces a new function fixSemicolonQuery in the server's main file to preprocess HTTP request URL queries. The function replaces semicolons with ampersands to address a Go warning related to query string parsing. The main function now includes a custom handler that wraps the default ServeMux, applying this query sanitization before request processing. This change enhances request handling without modifying the existing route structure.

Changes

File Change Summary
server/main.go Added fixSemicolonQuery function to sanitize URL query strings by replacing semicolons with ampersands; updated main function to use a custom handler that preprocesses incoming HTTP requests

Sequence Diagram

sequenceDiagram
    participant Client
    participant CustomHandler
    participant FixSemicolonQuery
    participant DefaultServeMux
    
    Client->>CustomHandler: Send HTTP Request
    CustomHandler->>FixSemicolonQuery: Preprocess Query
    FixSemicolonQuery-->>CustomHandler: Sanitized Query
    CustomHandler->>DefaultServeMux: Forward Request
    DefaultServeMux-->>Client: Response
Loading

Poem

🐰 A Rabbit's Query Fix 🔧

Semicolons dancing wild and free,
In URL strings, a quirky spree,
With gentle paws, I swap and mend,
Ampersands now my query's friend!
Go warns, but I just hop along 🦘

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9637565 and 4302f1c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json (5 hunks)
  • server/main.go (2 hunks)
🔇 Additional comments (2)
server/main.go (1)

83-89: 🛠️ Refactor suggestion

Consider edge cases in query parameter values.

The current implementation might incorrectly replace semicolons that are part of legitimate query parameter values (e.g., ?data=value;more). Consider URL-decoding the query string first, only replacing semicolons used as separators, and then URL-encoding the result.

 func fixSemicolonQuery(r *http.Request) {
 	if strings.Contains(r.URL.RawQuery, ";") {
-			r.URL.RawQuery = strings.ReplaceAll(r.URL.RawQuery, ";", "&")
+			// URL-decode the query string
+			decoded, err := url.QueryUnescape(r.URL.RawQuery)
+			if err != nil {
+				log.Printf("Warning: Failed to decode query string: %v", err)
+				return
+			}
+			// Replace semicolons between key-value pairs
+			parts := strings.Split(decoded, "&")
+			for i, part := range parts {
+				if !strings.Contains(part, "=") {
+					continue
+				}
+				parts[i] = strings.ReplaceAll(part, ";", "&")
+			}
+			// URL-encode and reassemble
+			r.URL.RawQuery = url.QueryEscape(strings.Join(parts, "&"))
 	}
 }

Additionally, consider adding debug logging to track when this function modifies queries:

 func fixSemicolonQuery(r *http.Request) {
 	if strings.Contains(r.URL.RawQuery, ";") {
+			original := r.URL.RawQuery
 			r.URL.RawQuery = strings.ReplaceAll(r.URL.RawQuery, ";", "&")
+			log.Printf("Modified query string: %s -> %s", original, r.URL.RawQuery)
 	}
 }
package.json (1)

Line range hint 81-205: Verify compatibility with updated dependencies.

While the dependency updates appear routine, please ensure that the following major version bumps have been tested thoroughly:

  • @sentry/react from version 7.x to 8.x
  • @testing-library/react from version 15.x to 16.x

@dqunbp dqunbp force-pushed the 16348-http-url-query-contains-semicolon-which-is-no-longer-a-supported-separator-1 branch from 4302f1c to 5731e63 Compare January 29, 2025 00:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4302f1c and 5731e63.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • server/main.go (2 hunks)
🔇 Additional comments (3)
server/main.go (3)

83-89: Add metrics for query modifications.

As suggested in the previous review, it would be valuable to track how often queries are modified using Prometheus metrics.


115-119: Verify performance impact of query string modification.

The query string modification is applied to all requests, which could impact performance. Consider adding benchmarks to measure the impact.


83-89: Consider validating the query string before modification.

The function modifies the query string without validating its format. Consider adding basic validation to ensure the query string is well-formed before modification.

server/main.go Show resolved Hide resolved
server/main.go Show resolved Hide resolved
server/main.go Show resolved Hide resolved
@dqunbp dqunbp force-pushed the 16348-http-url-query-contains-semicolon-which-is-no-longer-a-supported-separator-1 branch from 5731e63 to 7aaca2a Compare January 29, 2025 00:59
Copy link

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

Copy link

Bundle size diff

Old size New size Diff
5.17 MB 5.17 MB 0 B (0.00%)

Copy link

Preview environments for this PR:

These previews are automatically updated with each commit.

Note: After a new deployment, it may take a few minutes for the changes to propagate and for caches to update. During this time, you might experience temporary loading issues or see an older version of the app. If the app fails to load, please wait a few minutes and try again.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
server/main.go (2)

83-89: 🧹 Nitpick (assertive)

Add request validation and improve error handling.

While the function serves its purpose, it could be more robust:

  1. Add request parameter validation
  2. Consider error handling for edge cases
 func fixSemicolonQuery(r *http.Request) {
+    if r == nil || r.URL == nil {
+        return
+    }
     if strings.Contains(r.URL.RawQuery, ";") {
-            r.URL.RawQuery = strings.ReplaceAll(r.URL.RawQuery, ";", "&")
+        oldQuery := r.URL.RawQuery
+        r.URL.RawQuery = strings.ReplaceAll(r.URL.RawQuery, ";", "&")
+        log.Printf("Modified query string from '%s' to '%s'", oldQuery, r.URL.RawQuery)
     }
 }

Note: The logging suggestion and indentation fix are duplicates of previous comments.


115-119: 🛠️ Refactor suggestion

Avoid using DefaultServeMux directly.

Using http.DefaultServeMux directly is not recommended for production as it's a global variable that could be modified by any package. Consider using a local ServeMux instance instead.

+func newServer() http.Handler {
+    mux := http.NewServeMux()
+    
+    // Register routes on mux instead of http.Handle
+    mux.Handle("/live", http.StripPrefix("/live", http.HandlerFunc(redirectWithDn1Params)))
+    mux.Handle("/live/", http.StripPrefix("/live/", http.HandlerFunc(redirectWithDn1Params)))
+    // ... register other routes
+    
+    // Wrap mux with the query fix middleware
+    return withQueryFix(mux)
+}
+
+func withQueryFix(next http.Handler) http.Handler {
+    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+        fixSemicolonQuery(r)
+        next.ServeHTTP(w, r)
+    })
+}

Note: The middleware pattern suggestion is a duplicate of a previous comment.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5731e63 and 1de8774.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • server/main.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
server/main.go (1)

121-126: Improve server startup logging and error handling.

The current error handling could be more informative and follow better logging practices.

server/main.go Show resolved Hide resolved
@dqunbp dqunbp force-pushed the 16348-http-url-query-contains-semicolon-which-is-no-longer-a-supported-separator-1 branch from 1de8774 to 7aaca2a Compare January 29, 2025 19:04
@dqunbp dqunbp marked this pull request as draft February 5, 2025 19:13
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.

1 participant