Skip to content

Commit fe95e22

Browse files
committed
fix(ssurl): check base64 padding for correct config
1 parent e3c5463 commit fe95e22

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

crates/shadowsocks/src/config.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
time::Duration,
1313
};
1414

15-
use base64::{decode_config, encode_config, URL_SAFE_NO_PAD};
15+
use base64::{decode_config, encode_config, URL_SAFE, URL_SAFE_NO_PAD};
1616
use byte_string::ByteStr;
1717
use bytes::Bytes;
1818
use cfg_if::cfg_if;
@@ -668,6 +668,9 @@ impl ServerConfig {
668668
(m, p)
669669
}
670670
None => {
671+
// userinfo is not required to be percent encoded, but some implementation did.
672+
// If the base64 library have padding = added to the encoded string, then it will become %3D.
673+
671674
let decoded_user_info = match percent_encoding::percent_decode_str(user_info).decode_utf8() {
672675
Ok(m) => m,
673676
Err(err) => {
@@ -676,7 +679,15 @@ impl ServerConfig {
676679
}
677680
};
678681

679-
let account = match decode_config(decoded_user_info.to_string(), URL_SAFE_NO_PAD) {
682+
let decoded_user_info: &str = &decoded_user_info;
683+
let base64_config = if decoded_user_info.ends_with('=') {
684+
// Some implementation, like outline, or those with Python (base64 in Python will still have '=' padding for URL safe encode)
685+
URL_SAFE
686+
} else {
687+
URL_SAFE_NO_PAD
688+
};
689+
690+
let account = match decode_config(decoded_user_info, base64_config) {
680691
Ok(account) => match String::from_utf8(account) {
681692
Ok(ac) => ac,
682693
Err(..) => return Err(UrlParseError::InvalidAuthInfo),

0 commit comments

Comments
 (0)