Commit Graph

3715 Commits (ba10e68d01399fe34e15b84e63164a85c3dab6fb)

Author SHA1 Message Date
Jason McNeil ba10e68d01
test(middleware/csrf): Fix Benchmark Tests (#2932)
* test(middleware/csrf): fix Benchmark_Middleware_CSRF_*

* fix(middleware/csrf): update refererMatchesHost()
2024-03-25 15:30:20 +01:00
Jason McNeil 1607d872d9
fix(middleware/cors): Categorize requests correctly (#2921)
* fix(middleware/cors): categorise requests correctly

* test(middleware/cors): improve test coverage for request types

* test(middleware/cors): Add subdomain matching tests

* test(middleware/cors): parallel tests for CORS headers based on request type

* test(middleware/cors): Add benchmark for CORS subdomain matching

* test(middleware/cors): cover additiona test cases

* refactor(middleware/cors): origin validation and normalization
2024-03-20 14:57:29 +01:00
Jason McNeil 1aac6f618b
fix(middleware/cors): Handling and wildcard subdomain matching (#2915)
* fix: allow origins check

Refactor CORS origin validation and normalization to trim leading or trailing whitespace in the cfg.AllowOrigins string [list]. URLs with whitespace inside the URL are invalid, so the normalizeOrigin will return false because url.Parse will fail, and the middleware will panic.

fixes #2882

* test: AllowOrigins with whitespace

* test(middleware/cors): add benchmarks

* chore: fix linter errors

* test(middleware/cors): use h() instead of app.Test()

* test(middleware/cors): add miltiple origins in Test_CORS_AllowOriginScheme

* chore: refactor validate and normalize

* test(cors/middleware): add more benchmarks

* fix(middleware/cors): handling and wildcard subdomain matching

docs(middleware/cors): add How it works and Security Considerations

* chore: grammar

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: fix misspelling

* test(middleware/cors): combine Invalid_Origins tests

* refactor(middleware/cors): headers handling

* docs(middleware/cors): Update AllowOrigins description

* chore: merge

* perf(middleware/cors): optimize handler

* perf(middleware/cors): optimize handler

* chore(middleware/cors): ipdate origin handling logic

* chore(middleware/cors): fix header capitalization

* docs(middleware/cors): improve sercuity notes

* docs(middleware/cors): Improve security notes

* docs(middleware/cors): improve CORS overview

* docs(middleware/cors): fix ordering of how it works

* docs(middleware/cors): add additional info to How to works

* docs(middleware/cors): rm space

* docs(middleware/cors): add validation for AllowOrigins origins to overview

* docs(middleware/cors): update ExposeHeaders and MaxAge descriptions

* docs(middleware/cors): Add dynamic origin validation example

* docs(middleware/cors): Improve security notes and fix header capitalization

* docs(middleware/cors): configuration examples

* docs(middleware/cors): `"*"`

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-03-17 13:43:16 +01:00
René d2b19e290d refactor(docs): deactivate docs sync for v2 2024-03-02 19:14:29 +01:00
René 68d90cd6b2 refactor(docs): deactivate docs sync for v2 2024-03-02 19:13:07 +01:00
RW 109e91a630
prepare release v2.52.2 2024-03-02 18:56:50 +01:00
Jason McNeil d456e7d82e
fix(middleware/cors): Validation of multiple Origins (#2883)
* fix: allow origins check

Refactor CORS origin validation and normalization to trim leading or trailing whitespace in the cfg.AllowOrigins string [list]. URLs with whitespace inside the URL are invalid, so the normalizeOrigin will return false because url.Parse will fail, and the middleware will panic.

fixes #2882

* test: AllowOrigins with whitespace

* test(middleware/cors): add benchmarks

* chore: fix linter errors

* test(middleware/cors): use h() instead of app.Test()

* test(middleware/cors): add miltiple origins in Test_CORS_AllowOriginScheme

* chore: refactor validate and normalize

* test(cors/middleware): add more benchmarks
2024-03-01 10:31:11 +01:00
René Werner ddc6b231f8 fix sync-docs workflow 2024-02-21 21:54:55 +01:00
René Werner 0df0e0855d fix sync-docs workflow 2024-02-21 21:43:28 +01:00
René Werner 70f21d5f7e fix cors domain normalize 2024-02-21 21:18:56 +01:00
RW f9fcb0297c
Update app.go
prepare release v2.52.1
2024-02-21 17:03:00 +01:00
Juan Calderon-Perez f0cd3b44b0
Merge pull request from GHSA-fmg4-x8pw-hjhg
* Enforce Wildcard Origins with AllowCredentials check

* Expand unit-tests, fix issues with subdomains logic, update docs

* Update cors.md

* Added test using localhost, ipv4, and ipv6 address

* improve documentation markdown

---------

Co-authored-by: René Werner <rene@gofiber.io>
2024-02-21 14:47:33 +01:00
Lucas Lemos 5e30112d08
fix: healthcheck middleware not working with route group (#2863)
* fix: healthcheck middleware not working with route group

* perf: change verification method to improve perf

* Update healthcheck_test.go

* test: add not matching route test for strict routing

* add more test cases

* correct tests

* correct test helpers

* correct tests

* correct tests

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: René Werner <rene@gofiber.io>
2024-02-19 14:28:58 +01:00
Juan Calderon-Perez cf54c257e9
Merge pull request #2867 from grivera64/v2
📚 Doc: Fix code snippet indentation in /docs/api/middleware/keyauth.md
2024-02-18 21:40:18 -05:00
Giovanni Rivera a84a7cee7e
📚 Doc: Fix code snippet indentation in /docs/api/middleware/keyauth.md
Removes an an extra level of indentation in line 51 of
`keyauth.md` [here](https://github.com/gofiber/fiber/blob/v2/docs/api/middleware/keyauth.md?plain=1#L51)
2024-02-18 18:21:23 -08:00
RW 4e0f180fe3
Update routing.md 2024-02-08 08:18:26 +01:00
RW 56d2ec7bd0
Update ctx.md 2024-02-06 09:11:21 +01:00
René Werner 8325ed086c update queryParser config 2024-02-06 08:40:32 +01:00
Jongmin Kim e524b73524
Fix default value to false in docs of QueryBool (#2811)
fix default value to false in docs of QueryBool
2024-01-28 18:28:47 +01:00
René Werner 7ba3137f2e configure workflows for V2 branch 2024-01-06 17:45:21 +01:00
René Werner 2e66937b4e configure workflows for V2 branch 2024-01-06 17:36:42 +01:00
René Werner 476e1ed9fe fix healthcheck.md 2024-01-05 14:36:18 +01:00
René Werner 89f551becc prepare release v2.52.0
- add more Parser tests
2024-01-05 14:02:59 +01:00
Lucas Lemos 6249bc48bc
feat: add liveness and readiness checks (#2509)
*  feat: add liveness and readiness checkers

* 📝 docs: add docs for liveness and readiness

*  feat: add options method for probe checkers

*  tests: add tests for liveness and readiness

* ♻️ refactor: change default endpoint values

* ♻️ refactor: change default value for liveness endpoint

* 📝 docs: add return status for liveness and readiness probes

* ♻️ refactor: change probechecker to middleware

* 📝 docs: move docs to middleware session

* ♻️ refactor: apply gofumpt formatting

* ♻️ refactor: remove unused parameter

* split config and apply a review

* apply reviews and add testcases

* add benchmark

* cleanup

* rename middleware

* fix linter

* Update docs and config values

* Revert change to IsReady

* Updates based on code review

* Update docs to match other middlewares

---------

Co-authored-by: Muhammed Efe Cetin <efectn@protonmail.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: Juan Calderon-Perez <jgcalderonperez@protonmail.com>
2024-01-03 18:13:58 +01:00
RW 38eb4bd238
♻️ logger/middleware colorize logger error message #2593 (#2773) 2023-12-23 08:31:58 +01:00
gilwo d6c88764eb
🩹🚨 - fix for redirect with query params (#2748)
* redirect with query params did not work, fix it and add test for it

* redirect middleware - fix test typo
2023-12-22 16:18:04 +01:00
RW c49faf9a8a
🐛 [Bug]: Adaptator + otelfiber issue #2641 (#2772) 2023-12-22 14:49:58 +01:00
Muhammad Kholid B 1fac52a42a
🩹 Fix: CORS middleware should use the defined AllowedOriginsFunc config when AllowedOrigins is empty (#2771) 2023-12-22 14:48:37 +01:00
RW 43fa236d99
Update hooks.md
fix wrong hooks signature
2023-12-19 13:27:10 +01:00
Bruno dc2d2ef524
Changing default log output (#2730)
changing default log output

Closes #2729
2023-12-18 15:20:18 +01:00
dependabot[bot] b0925dc454
build(deps): bump github/codeql-action from 2 to 3 (#2763)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-16 13:30:45 +03:00
dependabot[bot] c3fed55744
build(deps): bump github.com/google/uuid from 1.4.0 to 1.5.0 (#2762)
Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.4.0 to 1.5.0.
- [Release notes](https://github.com/google/uuid/releases)
- [Changelog](https://github.com/google/uuid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/google/uuid/compare/v1.4.0...v1.5.0)

---
updated-dependencies:
- dependency-name: github.com/google/uuid
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-13 15:53:13 +03:00
Mehmet Firat KOMURCU 090acbbc5d
📚 Update app.md for indentation (#2761)
Update app.md for indentation
2023-12-13 08:52:16 +01:00
Benjamin Grosse b1850834a3
fix: don't constrain middlewares' context-keys to strings 🐛 (#2751)
* Revert "Revert "🐛 requestid.Config.ContextKey is interface{} (#2369)" (#2742)"

This reverts commit 28be17f929.

* fix: request ContextKey default value condition

Should check for `nil` since it is `any`.

* fix: don't constrain middlewares' context-keys to strings

`context` recommends using "unexported type" as context keys to avoid
collisions https://pkg.go.dev/github.com/gofiber/fiber/v2#Ctx.Locals.

The official go blog also recommends this https://go.dev/blog/context.

`fiber.Ctx.Locals(key any, value any)` correctly allows consumers to
use unexported types or e.g. strings.

But some fiber middlewares constrain their context-keys to `string` in
their "default config structs", making it impossible to use unexported
types.

This PR removes the `string` _constraint_ from all middlewares, allowing
to now use unexported types as per the official guidelines. However
the default value is still a string, so it's not a breaking change, and
anyone still using strings as context keys is not affected.
2023-12-12 14:55:29 +01:00
iRedMail c441bdf2d0
🩹 middleware/logger/: log client IP address by default (#2755)
* middleware/logger: Log client IP address by default.

* Update doc.
2023-12-08 10:36:43 +01:00
dependabot[bot] 8aa88689ae
build(deps): bump actions/setup-go from 4 to 5 (#2754)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-07 15:14:33 +01:00
Jason McNeil e4d7e84335
chore(encryptcookie)!: update default config (#2753)
* chore(encryptcookie)!: update default config

docs(encryptcookie): enhance documentation and examples

BREAKING CHANGE: removed the hardcoded "csrf_" from the Except.

* docs(encryptcookie): reads or modifies cookies

* chore(encryptcookie): csrf config example

* docs(encryptcookie): md table spacing
2023-12-07 08:39:41 +01:00
tokelo-12 a80b288592
Update CONTRIBUTING.md (#2752)
Grammar correction.
2023-12-05 15:21:03 +01:00
RW 9bcc7f3978
Update v3-changes.md 2023-12-03 10:20:29 +01:00
RW 2d3027eaba
Update pull_request_template.md 2023-12-03 10:19:13 +01:00
dependabot[bot] fa30b4e9d0
build(deps): bump golang.org/x/sys from 0.14.0 to 0.15.0 (#2744)
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.14.0 to 0.15.0.
- [Commits](https://github.com/golang/sys/compare/v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-28 22:42:05 +03:00
nickajacks1 8d5248bee6
🚨 Test: race in session middleware tests (#2740)
A Session must not be accessed after Save() is called, but a unit test
calls Session.ID() after Session.Save(), sometimes causing the test to
fail when -race is enabled. The assertions that ID() was being used in
were redundant with the previous two assertions (checking that the
session name header is empty), so we can just remove the offending code.
2023-11-27 14:38:31 +01:00
RW 28be17f929
Revert "🐛 requestid.Config.ContextKey is interface{} (#2369)" (#2742)
This reverts commit d7b36cde
2023-11-27 14:35:49 +01:00
nickajacks1 6b9630b5f7
🚨 Test: improve benchmarks for getOffer (#2739) 2023-11-23 09:36:22 +01:00
dependabot[bot] 93c5f2830f
build(deps): bump github.com/valyala/fasthttp from 1.50.0 to 1.51.0 (#2721)
Bumps [github.com/valyala/fasthttp](https://github.com/valyala/fasthttp) from 1.50.0 to 1.51.0.
- [Release notes](https://github.com/valyala/fasthttp/releases)
- [Commits](https://github.com/valyala/fasthttp/compare/v1.50.0...v1.51.0)

---
updated-dependencies:
- dependency-name: github.com/valyala/fasthttp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-22 20:12:15 +01:00
nickajacks1 eeced206ed
test: Fix failing CSRF tests (#2720)
 test: fix failing csrf test

A test validating that expired tokens fail was hitting a race condition
with garbage collection. Sometimes, an assertion that expects memory
storage GC to have triggered happens too quickly, causing the assertion
to fail. Give the GC a little bit more time to process before asserting.
2023-11-22 19:21:30 +01:00
nickajacks1 12e0e487ce
🚨 Test: fix race condition in parallel tests (#2734)
Tests that call SetParserDecoder were causing a race condition with
other tests that read from decoderPoolMap. Fix by making the offending
tests not run in parallel.
2023-11-22 18:38:49 +01:00
Jmper 2c5d883a69
[Bug]: utils.IsIPv4 and net.ParseIP have inconsistent results #2735 (#2736) 2023-11-21 10:48:37 +01:00
Jason McNeil 2374cad3cd
📄 docs: improve csrf docs (#2726)
* docs: improve csrf docs

- fix issues with `X-Csrf-Token` capitalization inconsistency.
- reduce redundancy and repetition.
- improve grammar.

* docs: update middleware description

* docs: within vs in

* docs: deleting tokens

* docs: MUST

* docs: add colon

* docs: all modern browsers

* docs: patterns

* docs: improve phrasing of pattern options
2023-11-16 12:34:31 +01:00
René Werner 3ab3d151c7 refresh docs for
🔥 Add support for application/problem+json #2704
2023-11-15 09:23:08 +01:00