Skip to content

Commit a274da0

Browse files
authored
Merge branch 'main' into fix/csrf-referer-origin-matching
2 parents 4d6aa5a + 5de4c35 commit a274da0

8 files changed

Lines changed: 38 additions & 19 deletions

File tree

.github/workflows/dependabot_automerge.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ jobs:
1111
if: ${{ github.actor == 'dependabot[bot]' }}
1212
steps:
1313
- name: Wait for check is finished
14-
uses: lewagon/wait-on-check-action@v1.6.1
1514
id: wait_for_checks
15+
uses: poseidon/wait-for-status-checks@v0.6.0
1616
with:
17-
ref: ${{ github.event.pull_request.head.sha || github.sha }}
18-
running-workflow-name: wait_for_checks
19-
check-regexp: unit
20-
repo-token: ${{ secrets.PR_TOKEN }}
21-
wait-interval: 10
17+
token: ${{ secrets.PR_TOKEN }}
18+
match_pattern: ^unit
19+
interval: 10
20+
timeout: 600
2221
dependabot:
2322
needs: [wait_for_checks]
2423
name: Dependabot auto-merge

app.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,19 @@ func (app *App) Test(req *http.Request, config ...TestConfig) (*http.Response, e
12131213
req.Header.Add(HeaderContentLength, strconv.FormatInt(req.ContentLength, 10))
12141214
}
12151215

1216+
// Ensure Host header is present in the dump (required by fasthttp)
1217+
if req.Host == "" {
1218+
if req.URL != nil && req.URL.Host != "" {
1219+
req.Host = req.URL.Host
1220+
} else {
1221+
req.Host = "localhost"
1222+
}
1223+
}
1224+
1225+
// Clear RequestURI so DumpRequest writes origin-form request line with
1226+
// Host header instead of absolute-form URI without Host header.
1227+
req.RequestURI = ""
1228+
12161229
// Dump raw http request
12171230
dump, err := httputil.DumpRequest(req, true)
12181231
if err != nil {

ctx_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5472,7 +5472,7 @@ func Test_Ctx_SendFile(t *testing.T) {
54725472

54735473
// test not modified
54745474
c = app.AcquireCtx(&fasthttp.RequestCtx{})
5475-
c.Request().Header.Set(HeaderIfModifiedSince, fI.ModTime().Format(time.RFC1123))
5475+
c.Request().Header.Set(HeaderIfModifiedSince, fI.ModTime().UTC().Format(http.TimeFormat))
54765476
err = c.SendFile("ctx.go")
54775477
// check expectation
54785478
require.NoError(t, err)

middleware/basicauth/basicauth_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,13 @@ func Test_BasicAuth_HeaderControlCharEdges(t *testing.T) {
406406

407407
handler := app.Handler()
408408
creds := base64.StdEncoding.EncodeToString([]byte("john:doe"))
409+
// Note: \r and \n are sanitized to spaces by fasthttp at the protocol level,
410+
// so we use other control chars (SOH, BEL) that pass through unchanged.
409411
headers := [][]byte{
410-
[]byte("\rBasic " + creds),
411-
[]byte("\nBasic " + creds),
412-
[]byte("Basic " + creds + "\r"),
413-
[]byte("Basic " + creds + "\n"),
412+
[]byte("\x01Basic " + creds),
413+
[]byte("\x07Basic " + creds),
414+
[]byte("Basic " + creds + "\x01"),
415+
[]byte("Basic " + creds + "\x07"),
414416
}
415417

416418
for _, h := range headers {

middleware/cache/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ func Test_CacheExpiresFutureAllowsCaching(t *testing.T) {
16471647
var count int
16481648
app.Get("/", func(c fiber.Ctx) error {
16491649
count++
1650-
c.Set(fiber.HeaderExpires, time.Now().Add(30*time.Second).UTC().Format(time.RFC1123))
1650+
c.Set(fiber.HeaderExpires, time.Now().Add(30*time.Second).UTC().Format(http.TimeFormat))
16511651
return c.SendString("expires" + strconv.Itoa(count))
16521652
})
16531653

@@ -1675,7 +1675,7 @@ func Test_CacheExpiresPastPreventsCaching(t *testing.T) {
16751675
var count int
16761676
app.Get("/", func(c fiber.Ctx) error {
16771677
count++
1678-
c.Set(fiber.HeaderExpires, time.Now().Add(-1*time.Minute).UTC().Format(time.RFC1123))
1678+
c.Set(fiber.HeaderExpires, time.Now().Add(-1*time.Minute).UTC().Format(http.TimeFormat))
16791679
return c.SendString("expires" + strconv.Itoa(count))
16801680
})
16811681

@@ -4671,7 +4671,7 @@ func Test_Cache_RequestResponseDirectives(t *testing.T) {
46714671
app := fiber.New()
46724672
app.Use(New(Config{Expiration: 1 * time.Hour}))
46734673
app.Get("/test", func(c fiber.Ctx) error {
4674-
futureTime := time.Now().Add(1 * time.Hour).Format(time.RFC1123)
4674+
futureTime := time.Now().Add(1 * time.Hour).UTC().Format(http.TimeFormat)
46754675
c.Response().Header.Set("Expires", futureTime)
46764676
return c.SendString("test")
46774677
})

middleware/session/data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var dataPool = sync.Pool{
3333
func acquireData() *data {
3434
obj := dataPool.Get()
3535
if d, ok := obj.(*data); ok {
36+
d.Reset()
3637
return d
3738
}
3839
// Handle unexpected type in the pool

middleware/static/static.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,16 @@ func New(root string, cfg ...Config) fiber.Handler {
163163
prefixLen--
164164
}
165165

166+
// For io/fs.FS, Root must be empty so fasthttp's pathToFilePath
167+
// returns clean relative paths without prefixing the root.
168+
// PathRewrite already handles file-root and subdirectory cases.
169+
fsRoot := root
170+
if config.FS != nil {
171+
fsRoot = ""
172+
}
173+
166174
fileServer := &fasthttp.FS{
167-
Root: root,
175+
Root: fsRoot,
168176
FS: config.FS,
169177
AllowEmptyRoot: true,
170178
GenerateIndexPages: config.Browse,

res.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,6 @@ func (r *DefaultRes) SendFile(file string, config ...SendFile) error {
835835
},
836836
}
837837

838-
if cfg.FS != nil {
839-
fasthttpFS.Root = "."
840-
}
841-
842838
sf := &sendFileStore{
843839
config: cfg,
844840
handler: fasthttpFS.NewRequestHandler(),

0 commit comments

Comments
 (0)