Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
a84604dc
Commit
a84604dc
authored
Feb 07, 2026
by
yangjianbo
Browse files
fix(config): 禁止 server.frontend_url 携带 query/userinfo
parent
e75d3e35
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/config/config.go
View file @
a84604dc
...
@@ -957,6 +957,16 @@ func (c *Config) Validate() error {
...
@@ -957,6 +957,16 @@ func (c *Config) Validate() error {
if
err
:=
ValidateAbsoluteHTTPURL
(
c
.
Server
.
FrontendURL
);
err
!=
nil
{
if
err
:=
ValidateAbsoluteHTTPURL
(
c
.
Server
.
FrontendURL
);
err
!=
nil
{
return
fmt
.
Errorf
(
"server.frontend_url invalid: %w"
,
err
)
return
fmt
.
Errorf
(
"server.frontend_url invalid: %w"
,
err
)
}
}
u
,
err
:=
url
.
Parse
(
strings
.
TrimSpace
(
c
.
Server
.
FrontendURL
))
if
err
!=
nil
{
return
fmt
.
Errorf
(
"server.frontend_url invalid: %w"
,
err
)
}
if
u
.
RawQuery
!=
""
||
u
.
ForceQuery
{
return
fmt
.
Errorf
(
"server.frontend_url invalid: must not include query"
)
}
if
u
.
User
!=
nil
{
return
fmt
.
Errorf
(
"server.frontend_url invalid: must not include userinfo"
)
}
warnIfInsecureURL
(
"server.frontend_url"
,
c
.
Server
.
FrontendURL
)
warnIfInsecureURL
(
"server.frontend_url"
,
c
.
Server
.
FrontendURL
)
}
}
if
c
.
JWT
.
ExpireHour
<=
0
{
if
c
.
JWT
.
ExpireHour
<=
0
{
...
...
backend/internal/config/config_test.go
View file @
a84604dc
...
@@ -437,6 +437,21 @@ func TestValidateServerFrontendURL(t *testing.T) {
...
@@ -437,6 +437,21 @@ func TestValidateServerFrontendURL(t *testing.T) {
t
.
Fatalf
(
"Validate() frontend_url valid error: %v"
,
err
)
t
.
Fatalf
(
"Validate() frontend_url valid error: %v"
,
err
)
}
}
cfg
.
Server
.
FrontendURL
=
"https://example.com/path"
if
err
:=
cfg
.
Validate
();
err
!=
nil
{
t
.
Fatalf
(
"Validate() frontend_url with path valid error: %v"
,
err
)
}
cfg
.
Server
.
FrontendURL
=
"https://example.com?utm=1"
if
err
:=
cfg
.
Validate
();
err
==
nil
{
t
.
Fatalf
(
"Validate() should reject server.frontend_url with query"
)
}
cfg
.
Server
.
FrontendURL
=
"https://user:pass@example.com"
if
err
:=
cfg
.
Validate
();
err
==
nil
{
t
.
Fatalf
(
"Validate() should reject server.frontend_url with userinfo"
)
}
cfg
.
Server
.
FrontendURL
=
"/relative"
cfg
.
Server
.
FrontendURL
=
"/relative"
if
err
:=
cfg
.
Validate
();
err
==
nil
{
if
err
:=
cfg
.
Validate
();
err
==
nil
{
t
.
Fatalf
(
"Validate() should reject relative server.frontend_url"
)
t
.
Fatalf
(
"Validate() should reject relative server.frontend_url"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment