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(wren-ui): encode pwd when building connection url #1281

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

Conversation

onlyjackfrost
Copy link
Contributor

@onlyjackfrost onlyjackfrost commented Feb 10, 2025

Description

encode pwd when building connection url

Issue

#1278

Summary by CodeRabbit

  • Bug Fixes
    • Improved secure handling for data source connections so that credentials with special characters won’t disrupt connectivity.

Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

The pull request modifies the connection URL construction in the data source file. The password for both the Postgres and Click House data sources is now URL-encoded using encodeURIComponent() before being embedded in the connection URL. This change ensures that any special characters in the password do not disrupt the URL format. No exported or public entity declarations have been altered.

Changes

File(s) Change Summary
wren-ui/.../dataSource.ts Updated connection URL construction for Postgres and Click House by URL-encoding the password using encodeURIComponent(), handling special characters.

Suggested reviewers

  • wwwy3y3

Poem

I’m a little rabbit hopping through code,
Encrypting secrets on my digital road.
Passwords now safe with each encode,
Special symbols lighten my joyful mode.
With every keystroke, I cheer and quip—
Carrots and code, what a fun partnership!
Hop on, dear devs, to a secure new script!

✨ 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: 0

🧹 Nitpick comments (1)
wren-ui/src/apollo/server/dataSource.ts (1)

171-172: Add comment for consistency with Postgres implementation.

The implementation correctly uses encodeURIComponent(), matching the Postgres changes.

Add a comment for consistency with the Postgres implementation:

+ // url encode password
  const encodedPassword = encodeURIComponent(password);
  let connectionUrl = `clickhouse://${user}:${encodedPassword}@${host}:${port}/${database}?`;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3793455 and 20b6640.

📒 Files selected for processing (1)
  • wren-ui/src/apollo/server/dataSource.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
wren-ui/src/apollo/server/dataSource.ts (1)

101-104: LGTM! Verify password encoding with special characters.

The implementation correctly uses encodeURIComponent() to encode the password in the Postgres connection URL.

Please verify that the encoding works correctly with passwords containing special characters like:

  • Spaces
  • Special characters (@#$%^&*)
  • Unicode characters
  • URL-specific characters (:/?#[]@)
✅ Verification successful

🌐 Web query:

What characters does encodeURIComponent() encode in JavaScript?

💡 Result:

The `encodeURIComponent()` function in JavaScript encodes all characters except the following **unreserved characters**:  
`A-Z a-z 0-9 - _ . ! ~ * ' ( )`[3][7][8].  

It specifically encodes these **reserved/special characters** used in URI components:  
```
, / ? : @ & = + $ #  
```  
and other unsafe/non-ASCII characters like spaces (`%20`), percent signs (`%25`), quotation marks (`%22`), etc.[1][3][4][5][7].

### Key Details:  
1. **Encodes more aggressively than `encodeURI()`**  
   While `encodeURI()` preserves URI syntax characters (like `/`, `:`, and `@`), `encodeURIComponent()` encodes them[3][6][8]:  
   ```javascript
   encodeURIComponent("/?:@&=+$#") 
   // → "%2F%3F%3A%40%26%3D%2B%24%23"
   ```

2. **Use case**  
   Designed for encoding **URI components** (like query parameters), not full URLs[3][4][6]:  
   ```javascript
   const param = "price=100$&color=red";
   const encoded = encodeURIComponent(param); 
   // → "price%3D100%24%26color%3Dred"
   ```

3. **Special character replacements**  
   - Space → `%20` (not `+` like in form encoding)[4][7]  
   - `&` → `%26`[1][5]  
   - `=` → `%3D`[5]  
   - `#` → `%23`[5]

### Comparison Table: encodeURI vs encodeURIComponent
| Character | encodeURI | encodeURIComponent |
|-----------|-----------|--------------------|
| `/`       | No        | Yes (`%2F`)       |
| `:`       | No        | Yes (`%3A`)       |
| `@`       | No        | Yes (`%40`)       |
| `&`       | No        | Yes (`%26`)       |
| `=`       | No        | Yes (`%3D`)       |
| `+`       | No        | Yes (`%2B`)       |
| `$`       | No        | Yes (`%24`)       |
| `,`       | No        | Yes (`%2C`)       |

Use `encodeURIComponent()` when encoding values for URL components like query parameters or hash fragments[3][4][6]. For complete URLs with intact domain/path structure, use `encodeURI()` instead[3][8].

Citations:

- 1: https://www.w3schools.com/jsref/jsref_encodeuricomponent.asp
- 2: https://www.boardinfinity.com/blog/encoding-and-decoding-url-in-javascript-how/
- 3: https://www.30secondsofcode.org/js/s/encodeuri-encodeuricomponent/
- 4: https://frontendmasters.com/blog/encoding-and-decoding-urls-in-javascript/
- 5: https://documentation.n-able.com/N-central/userguide/Content/Further_Reading/API_Level_Integration/API_Integration_URLEncoding.html
- 6: https://love2dev.com/blog/whats-the-difference-between-encodeuri-and-encodeuricomponent/
- 7: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent...
- 8: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
- 9: http://www.w3schools.com/Jsref/jsref_encodeuri.asp
- 10: https://phpgrid.com/blog/when-to-use-encodeuri-and-encodeuricomponent/

Password Encoding Verified!

The code correctly uses encodeURIComponent() to encode the password in the connection URL. As confirmed by the web query, this function encodes all reserved/special characters (such as spaces, @, $, %, &, etc.) except for the unreserved characters. This ensures that passwords with special characters will be handled safely in the connection string.

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