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: special characters in the URL's password #317

Merged
merged 2 commits into from
Sep 28, 2021

Conversation

biluohc
Copy link
Contributor

@biluohc biluohc commented Sep 22, 2021

No description provided.

@biluohc biluohc changed the title fix special characters in the URL's password fix: special characters in the URL's password Sep 22, 2021
utils/utils.ts Outdated
// Special characters in the password may be url-encoded by URL(), such as =
try {
password = decodeURIComponent(password);
} catch (error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A ConnectionParamsError must be thrown here if the password encoding fails

Copy link
Contributor Author

@biluohc biluohc Sep 25, 2021

Choose a reason for hiding this comment

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

I mean is that even if the decoding fails, the password is not decoded, which is the current behavior. If an error is to be thrown, I am not sure if there will be an abnormality after the change that the current version can run normally.

In fact, if creating a new URL object success, and then url-decoding the password of the url will not fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found one that failed, probably shouldn't throw an error

> let u = new URL('mysql://root:Mtx%3@loalhost:9999/txdb')
undefined
> u
URL {
  href: "mysql://root:Mtx%3@loalhost:9999/txdb",
  origin: "null",
  protocol: "mysql:",
  username: "root",
  password: "Mtx%3",
  host: "loalhost:9999",
  hostname: "loalhost",
  port: "9999",
  pathname: "/txdb",
  hash: "",
  search: ""
}
> decodeURIComponent(u.password)
Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at <anonymous>:2:1
> let password = u.password;
undefined
> password
"Mtx%3"
> try {
    password = decodeURIComponent(password);
  } catch (error) {}
undefined
> password
"Mtx%3"

Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest I'm not sure what to do regarding this. The most "correct" to me seems to ask users to encode the password beforehand, and not leave it up to us to check whether it's encoded or not, but I can see both cases being equally as valid

You know what? Just add a warning similar to

console.error(`${bold(yellow(warning.severity))}: ${warning.message}`);
indicating the user when the decoding fails and the driver will take the raw password

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, thanks, I added a console.error

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's leave it at

URL-encoded password decode failed
Defaulting to take the URL-encoded password

No other comments, please rebase over latest main because of a faulty commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already rebase over latest main.

utils/utils.ts Outdated
// Special characters in the password may be url-encoded by URL(), such as =
try {
password = decodeURIComponent(password);
} catch (error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest I'm not sure what to do regarding this. The most "correct" to me seems to ask users to encode the password beforehand, and not leave it up to us to check whether it's encoded or not, but I can see both cases being equally as valid

You know what? Just add a warning similar to

console.error(`${bold(yellow(warning.severity))}: ${warning.message}`);
indicating the user when the decoding fails and the driver will take the raw password

Copy link
Collaborator

@Soremwar Soremwar left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @biluohc

@Soremwar Soremwar merged commit 67e3098 into denodrivers:main Sep 28, 2021
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.

2 participants