Skip to content

Commit 2ce56d0

Browse files
committed
fix: Access-Control-Allow-Headers 的值为 * 时会额外包含 Authorization
1 parent 8ce82db commit 2ce56d0

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

.github/workflows/go.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ name: Go
22
on: [push, pull_request]
33

44
jobs:
5-
65
test:
76
name: Test
87
runs-on: ${{ matrix.os }}
98

109
strategy:
1110
matrix:
1211
os: [ubuntu-latest, macOS-latest, windows-latest]
13-
go: ['1.22.x', '1.23.x']
12+
go: ["1.23.x", "1.24.x"]
1413

1514
steps:
16-
1715
- name: Check out code into the Go module directory
1816
uses: actions/checkout@v4
1917

@@ -30,7 +28,7 @@ jobs:
3028
run: go test -race -v -coverprofile='coverage.txt' -covermode=atomic ./...
3129

3230
- name: Upload Coverage report
33-
uses: codecov/codecov-action@v4
31+
uses: codecov/codecov-action@v5
3432
with:
3533
token: ${{secrets.CODECOV_TOKEN}}
36-
file: ./coverage.txt
34+
files: ./coverage.txt

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/issue9/mux/v9
33
require (
44
github.com/issue9/assert/v4 v4.3.1
55
github.com/issue9/errwrap v0.3.2
6-
github.com/issue9/source v0.11.7
6+
github.com/issue9/source v0.12.5
77
)
88

9-
require golang.org/x/mod v0.22.0 // indirect
9+
require golang.org/x/mod v0.24.0 // indirect
1010

11-
go 1.22.0
11+
go 1.23.0

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ github.com/issue9/assert/v4 v4.3.1 h1:dHYODk1yV7j/1baIB6K6UggI4r1Hfuljqic7PaDbwL
22
github.com/issue9/assert/v4 v4.3.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
33
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
44
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
5-
github.com/issue9/source v0.11.7 h1:wyZv2MExD1kem7FGxIy6/iSgDHqNpLox6dAZfP7VzKM=
6-
github.com/issue9/source v0.11.7/go.mod h1:cmLmHZdgj+ONnGNdnJp++94VKXTszNAD99hAYOC22bU=
7-
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
8-
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
5+
github.com/issue9/source v0.12.5 h1:yfp7gZLMGArbpYgn3wEJ6WAXvx2dCknEXUec/+e3WyE=
6+
github.com/issue9/source v0.12.5/go.mod h1:5nOhQUwAwEjFVeFkY0QJgSEMsmwHxNugO9O4RhfLNH4=
7+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
8+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=

options.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2014-2024 caixw
1+
// SPDX-FileCopyrightText: 2014-2025 caixw
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -221,20 +221,14 @@ func (o *options) sanitize() error {
221221
}
222222

223223
func (c *cors) sanitize() error {
224-
for _, o := range c.Origins {
225-
if o == "*" {
226-
c.anyOrigins = true
227-
break
228-
}
224+
if slices.Contains(c.Origins, "*") {
225+
c.anyOrigins = true
229226
}
230227
c.deny = len(c.Origins) == 0
231228

232-
for _, h := range c.AllowHeaders {
233-
if h == "*" {
234-
c.allowHeadersString = "*"
235-
c.anyHeaders = true
236-
break
237-
}
229+
if slices.Contains(c.AllowHeaders, "*") {
230+
c.allowHeadersString = "*," + header.Authorization // Firefox 中 * 并不包含 Authorization 报头。
231+
c.anyHeaders = true
238232
}
239233
if c.allowHeadersString == "" && len(c.AllowHeaders) > 0 {
240234
c.allowHeadersString = strings.Join(c.AllowHeaders, ",")

options_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2014-2024 caixw
1+
// SPDX-FileCopyrightText: 2014-2025 caixw
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -149,7 +149,7 @@ func TestCORS_sanitize(t *testing.T) {
149149
}
150150
a.NotError(c.sanitize())
151151
a.True(c.anyHeaders).
152-
Equal(c.allowHeadersString, "*").
152+
Equal(c.allowHeadersString, "*,"+header.Authorization).
153153
Equal(c.exposedHeadersString, "h1,h2")
154154
}
155155

0 commit comments

Comments
 (0)