Skip to content

Commit f5389e2

Browse files
committed
refactor!: disable empty RESUful auth token
1 parent bb8ac6c commit f5389e2

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

tuic-server/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ hostname = "example.org" # Default: "localhost"
187187
# If you want disable RESTful function, remove entire `restful` section.
188188
[restful] # Default: empty
189189
addr = "127.0.0.1:8443" # Default: "127.0.0.1:8443"
190-
# Set secret to "" to disable authorization
191190
secret = "YOUR_SECRET_HERE" # Default: "YOUR_SECRET_HERE"
192191

193192
# Limit how many clients one uuid can have at the same time.

tuic-server/src/restful.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ pub async fn start(ctx: Arc<AppContext>) {
6767

6868
let mut traffic = HashMap::new();
6969
for (user, _) in ctx.cfg.users.iter() {
70-
// TODO use persist
7170
traffic.insert(user.to_owned(), (AtomicU64::new(0), AtomicU64::new(0)));
7271
}
7372

@@ -90,10 +89,11 @@ pub async fn start(ctx: Arc<AppContext>) {
9089

9190
async fn kick(
9291
State(ctx): State<Arc<AppContext>>,
93-
token: Authorization<Bearer>,
92+
token: TypedHeader<Authorization<Bearer>>,
9493
Json(users): Json<Vec<Uuid>>,
9594
) -> StatusCode {
9695
if let Some(restful) = &ctx.cfg.restful
96+
&& restful.secret == ""
9797
&& restful.secret != token.token()
9898
{
9999
return StatusCode::UNAUTHORIZED;
@@ -110,9 +110,10 @@ async fn kick(
110110

111111
async fn list_online(
112112
State(ctx): State<Arc<AppContext>>,
113-
token: Option<TypedHeader<Authorization<Bearer>>>,
113+
token: TypedHeader<Authorization<Bearer>>,
114114
) -> (StatusCode, Json<HashMap<Uuid, u64>>) {
115115
if let Some(restful) = &ctx.cfg.restful
116+
&& restful.secret == ""
116117
&& restful.secret != token.token()
117118
{
118119
return (StatusCode::UNAUTHORIZED, Json(HashMap::new()));
@@ -130,11 +131,10 @@ async fn list_online(
130131

131132
async fn list_detailed_online(
132133
State(ctx): State<Arc<AppContext>>,
133-
token: Option<TypedHeader<Authorization<Bearer>>>,
134+
token: TypedHeader<Authorization<Bearer>>,
134135
) -> (StatusCode, Json<HashMap<Uuid, Vec<SocketAddr>>>) {
135136
if let Some(restful) = &ctx.cfg.restful
136-
&& !restful.secret.is_empty()
137-
&& let Some(TypedHeader(token)) = token
137+
&& restful.secret == ""
138138
&& restful.secret != token.token()
139139
{
140140
return (StatusCode::UNAUTHORIZED, Json(HashMap::new()));
@@ -152,11 +152,10 @@ async fn list_detailed_online(
152152

153153
async fn list_traffic(
154154
State(ctx): State<Arc<AppContext>>,
155-
token: Option<TypedHeader<Authorization<Bearer>>>,
155+
token: TypedHeader<Authorization<Bearer>>,
156156
) -> (StatusCode, Json<HashMap<Uuid, serde_json::Value>>) {
157157
if let Some(restful) = &ctx.cfg.restful
158-
&& !restful.secret.is_empty()
159-
&& let Some(TypedHeader(token)) = token
158+
&& restful.secret == ""
160159
&& restful.secret != token.token()
161160
{
162161
return (StatusCode::UNAUTHORIZED, Json(HashMap::new()));
@@ -175,11 +174,10 @@ async fn list_traffic(
175174

176175
async fn reset_traffic(
177176
State(ctx): State<Arc<AppContext>>,
178-
token: Option<TypedHeader<Authorization<Bearer>>>,
177+
token: TypedHeader<Authorization<Bearer>>,
179178
) -> (StatusCode, Json<HashMap<Uuid, serde_json::Value>>) {
180179
if let Some(restful) = &ctx.cfg.restful
181-
&& !restful.secret.is_empty()
182-
&& let Some(TypedHeader(token)) = token
180+
&& restful.secret == ""
183181
&& restful.secret != token.token()
184182
{
185183
return (StatusCode::UNAUTHORIZED, Json(HashMap::new()));

0 commit comments

Comments
 (0)