Home / Function/ Test_CSRF_Cookie_Injection_Exploit() — fiber Function Reference

Test_CSRF_Cookie_Injection_Exploit() — fiber Function Reference

Architecture documentation for the Test_CSRF_Cookie_Injection_Exploit() function in csrf_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  4af969a2_2521_8a15_6417_7f430f35cfbf["Test_CSRF_Cookie_Injection_Exploit()"]
  306a0c68_f5a5_b368_f37a_1419425a8fea["csrf_test.go"]
  4af969a2_2521_8a15_6417_7f430f35cfbf -->|defined in| 306a0c68_f5a5_b368_f37a_1419425a8fea
  style 4af969a2_2521_8a15_6417_7f430f35cfbf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/csrf/csrf_test.go lines 1753–1784

func Test_CSRF_Cookie_Injection_Exploit(t *testing.T) {
	t.Parallel()
	app := fiber.New()

	app.Use(New())

	app.Post("/", func(c fiber.Ctx) error {
		return c.SendStatus(fiber.StatusOK)
	})

	h := app.Handler()
	ctx := &fasthttp.RequestCtx{}

	// Inject CSRF token
	ctx.Request.Reset()
	ctx.Response.Reset()
	ctx.Request.Header.SetMethod(fiber.MethodGet)
	ctx.Request.Header.Set(fiber.HeaderCookie, "csrf_=pwned;")
	ctx.Request.SetRequestURI("/")
	h(ctx)
	token := string(ctx.Response.Header.Peek(fiber.HeaderSetCookie))
	token = strings.Split(strings.Split(token, ";")[0], "=")[1]

	// Exploit CSRF token we just injected
	ctx.Request.Reset()
	ctx.Response.Reset()
	ctx.Request.Header.SetMethod(fiber.MethodPost)
	ctx.Request.Header.Set(HeaderName, token)
	ctx.Request.Header.Set(fiber.HeaderCookie, "csrf_=pwned;")
	h(ctx)
	require.Equal(t, 403, ctx.Response.StatusCode(), "CSRF exploit successful")
}

Subdomains

Frequently Asked Questions

What does Test_CSRF_Cookie_Injection_Exploit() do?
Test_CSRF_Cookie_Injection_Exploit() is a function in the fiber codebase, defined in middleware/csrf/csrf_test.go.
Where is Test_CSRF_Cookie_Injection_Exploit() defined?
Test_CSRF_Cookie_Injection_Exploit() is defined in middleware/csrf/csrf_test.go at line 1753.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free