Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies property is not populated #2070

Closed
mattjohnsonpint opened this issue Dec 2, 2022 · 2 comments · Fixed by #2411
Closed

Cookies property is not populated #2070

mattjohnsonpint opened this issue Dec 2, 2022 · 2 comments · Fixed by #2411
Assignees
Labels
ASP.NET Core ASP.NET Bug Something isn't working

Comments

@mattjohnsonpint
Copy link
Contributor

mattjohnsonpint commented Dec 2, 2022

Package

Sentry.AspNet
Sentry.AspNetCore

SDK Version

3.24.0

Steps to Reproduce

In an ASP.NET Core app (such as Sentry.Samples.AspNetCore.Basic):

Create a processor to log cookies to the console for both events and transactions:

public class MyProcessor : ISentryEventProcessor, ISentryTransactionProcessor
{
    private readonly SentryOptions _options;

    public MyProcessor(SentryOptions options)
    {
        _options = options;
    }

    public SentryEvent Process(SentryEvent @event)
    {
        _options.DiagnosticLogger?.LogInfo("Cookies: {0}", @event.Request.Cookies);
        return @event;
    }

    public Transaction Process(Transaction transaction)
    {
        _options.DiagnosticLogger?.LogInfo("Cookies: {0}", transaction.Request.Cookies);
        return transaction;
    }
}

Set options:

.UseSentry(options =>
{
    options.Debug = true;
    options.EnableTracing = true;
    options.SendDefaultPii = true;

    var processor = new MyProcessor(options);
    options.AddEventProcessor(processor);
    options.AddTransactionProcessor(processor);
})

Set a cookie in some endpoint:

endpoints.MapGet("/", (HttpContext context) =>
{
    context.Response.Cookies.Append("foo", "bar");
    return Results.Ok("Hello World!");
});

Run the app and load the page once to set the cookie, and then reload the page again so the browser sends the cookie in the request.

Actual Result

The console output shows:

Cookies: (null)

Expected Result

Cookies should be populated and set on the request (as long as SendDefaultPii == true)

https://develop.sentry.dev/sdk/event-payloads/request/

Applies to both ASP.Net Framework and ASP.Net Core

Cookies: foo=bar;
@mattjohnsonpint
Copy link
Contributor Author

mattjohnsonpint commented Dec 5, 2022

Note, we do send cookies already as a header in Request.Headers, and only when SendDefaultPii == true. So, this is mostly an annoyance when writing event/transaction processors, or in BeforeSend.

Relay will normalize Request.Cookies and cookies sent in Request.Headers, so they're treated the same by Sentry either way.

@kanadaj
Copy link
Contributor

kanadaj commented Dec 5, 2022

This is mainly an issue because the default filter for the Identity cookie does not work if the cookie got renamed, and filtering cookies in an unparsed header is far too involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASP.NET Core ASP.NET Bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants