Append a raw Set-Cookie header¶
This operation appends an additional Set-Cookie header value to the current response, deliberately bypassing Response.Cookies.Append's automatic URL-encoding so the raw Base64 cookie value a legacy reader expects is not altered. It is public on ILegacyAuthCookieService, so a consumer can use it to write any cookie this way, not only SAIFAUTH.
| Field | Value |
|---|---|
| Operation ID | OP-02 |
| Trigger | Called by Issue the legacy auth cookie step 5, or directly by a consumer |
| Inputs | cookie key, raw value, and the target HttpContext (an explicit parameter; the injected accessor is not used here) |
| Outputs | One extra Set-Cookie header value on context.Response.Headers |
| Primary components | LegacyAuthCookieService.AddCookieToHeader |
| Entry point | src/SAIF.NetCore.LegacyAuth/src/SAIF.NetCore.LegacyAuth/SAIF.NetCore.LegacyAuth/LegacyAuthCookieService.cs |
Steps¶
- Create a
SetCookieHeaderValue(key, value)withPath = "/"andHttpOnly = true(BR-05, BR-06) - On failure:
SetCookieHeaderValuevalidates the cookie name and value; an invalid cookie character throwsArgumentException(framework behavior)*. - Render it to a header string (BR-05)
- No URL-encoding is applied, leaving Base64 characters such as
+,/, and=raw. - Append the string to any existing
Set-Cookievalues withStringValues.Concat. - On failure: if the response has already started, setting headers throws
InvalidOperationException(framework behavior)*.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["Trigger: AddCookieToHeader called"]) --> S1["Build SetCookieHeaderValue:<br>Path=/, HttpOnly=true"]
S1 --> D1{Invalid cookie<br>character?}
D1 -->|Yes| ErrArg([ArgumentException])
D1 -->|No| S2["Render to header string<br>no URL-encoding"]
S2 --> S3["Append to existing<br>Set-Cookie values"]
S3 --> D2{Response already<br>started?}
D2 -->|Yes| ErrInv([InvalidOperationException])
D2 -->|No| EndOk([Header value appended])
Failure and edge-case behavior¶
- An invalid character in the cookie
keyorvaluethrowsArgumentExceptionfromSetCookieHeaderValue's own validation*. - Calling this operation after the response has already started sending throws
InvalidOperationExceptionfrom the underlyingHttpResponse.Headerssetter*. - Because no URL-encoding is applied, any raw Base64 ciphertext (including
+,/,=) is sent unmodified, which is required for the legacy reader to decrypt it correctly (BR-05)
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
src/SAIF.NetCore.LegacyAuth/src/SAIF.NetCore.LegacyAuth/SAIF.NetCore.LegacyAuth/LegacyAuthCookieService.cs