Skip to content

Commit

Permalink
fix: urldecode when influxdb auth (#2831)
Browse files Browse the repository at this point in the history
* fix: add url decode when influxdb auth

* chore: fmt toml
  • Loading branch information
fengys1996 authored Nov 28, 2023
1 parent e42767d commit 707a0d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ tonic-reflection = "0.10"
tonic.workspace = true
tower = { version = "0.4", features = ["full"] }
tower-http = { version = "0.3", features = ["full"] }
urlencoding = "2.1"

[target.'cfg(not(windows))'.dependencies]
tikv-jemalloc-ctl = { version = "0.5", features = ["use_std"] }
Expand Down
8 changes: 8 additions & 0 deletions src/servers/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ pub enum Error {
error: serde_json::error::Error,
location: Location,
},

#[snafu(display("Failed to decode url"))]
UrlDecode {
#[snafu(source)]
error: FromUtf8Error,
location: Location,
},
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -444,6 +451,7 @@ impl ErrorExt for Error {
| DataFrame { .. }
| PreparedStmtTypeMismatch { .. }
| TimePrecision { .. }
| UrlDecode { .. }
| IncompatibleSchema { .. } => StatusCode::InvalidArguments,

InfluxdbLinesWrite { source, .. }
Expand Down
6 changes: 4 additions & 2 deletions src/servers/src/http/authorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use super::header::GreptimeDbName;
use super::PUBLIC_APIS;
use crate::error::{
self, InvalidAuthorizationHeaderSnafu, InvalidParameterSnafu, InvisibleASCIISnafu,
NotFoundInfluxAuthSnafu, Result, UnsupportedAuthSchemeSnafu,
NotFoundInfluxAuthSnafu, Result, UnsupportedAuthSchemeSnafu, UrlDecodeSnafu,
};
use crate::http::HTTP_API_PREFIX;

Expand Down Expand Up @@ -166,7 +166,9 @@ fn get_influxdb_credentials<B: Send + Sync + 'static>(
return Ok(None);
};

match extract_influxdb_user_from_query(query_str) {
let query_str = urlencoding::decode(query_str).context(UrlDecodeSnafu)?;

match extract_influxdb_user_from_query(&query_str) {
(None, None) => Ok(None),
(Some(username), Some(password)) => {
Ok(Some((username.to_string(), password.to_string().into())))
Expand Down

0 comments on commit 707a0d5

Please sign in to comment.