aspnet / AspNetKatana

Microsoft's OWIN implementation, the Katana project
Apache License 2.0
968 stars 334 forks source link

Missing Parameters Without Values in IOwinRequest.Query Dictionary #540

Open chupAkabRRa opened 2 months ago

chupAkabRRa commented 2 months ago

Description

While creating a custom LoggingMiddleware, we encountered an issue where parameters without a value are not included in the IOwinRequest.Query dictionary. Our use case requires logging all parameters passed to our service, but parameters with no associated value and no "=" sign (e.g., ?param) are omitted from the query dictionary.

To resolve this, we had to manually parse the QueryString. This behavior is not explicitly documented, and it was unexpected.

Proposed Fix

I believe the issue lies in the ParseDelimited() method in src/Microsoft.Owin/Infrastructure/OwinHelpers.cs. The following check:

if (equalIndex < delimiterIndex)

ignores the possibility of parsing parameters without a corresponding value.

Steps to Reproduce

  1. Create a middleware that inspects the IOwinRequest.Query dictionary.
  2. Send a request with a query string containing parameters without values and without "=" sign (e.g., ?param1=1&param2).
  3. Notice that param2 is missing from the Query dictionary.