Issue the legacy auth cookie¶
This operation builds the tab-delimited credential payload, encrypts it with Windows DPAPI, and writes the resulting value as the SAIFAUTH response cookie so a legacy .NET Framework "SecurityModule" can authenticate the user on the same host.
| Field | Value |
|---|---|
| Operation ID | OP-01 |
| Trigger | A consuming application calls it after the user has authenticated, inferred to be while the plaintext password is still available* |
| Inputs | user, password; the ambient HttpContext from IHttpContextAccessor |
| Outputs | A Set-Cookie: SAIFAUTH=<base64>; path=/; httponly header appended to the current response. Returns void. |
| Primary components | LegacyAuthCookieService.SetCookie |
| Entry point | src/SAIF.NetCore.LegacyAuth/src/SAIF.NetCore.LegacyAuth/SAIF.NetCore.LegacyAuth/LegacyAuthCookieService.cs |
Steps¶
- Read the current
HttpContextfrom_httpContextAccessor.HttpContext. - On failure: outside an active request,
contextisnulland the next step throwsNullReferenceException(BR-10) - Build the plaintext payload
"{user}\t{password}\t"(BR-02) - Null
user/passwordinterpolate as empty strings; a tab character embedded in either value is not escaped and may corrupt the legacy reader's parsing*. - Take the client's remote IP address as a string to use as DPAPI entropy (BR-03)
- On failure:
RemoteIpAddresscan benullunder some in-process hosts, producingNullReferenceException(BR-10) - Encrypt the payload with DPAPI using the machine key scope, the IP entropy, and an empty description (BR-04)
- 4.1 Apply defaults through the overload chain down to the four-argument
Encrypt(KeyType, string, string, string)call (BR-07) - 4.2 Coerce a
nullplaintext or entropy argument to""(BR-08) - 4.3 UTF-8 encode the plaintext and entropy, then Base64-encode the returned ciphertext (BR-09)
- On failure: any exception raised inside the byte-array encrypt call's own try block is rethrown as
Exception("DPAPI was unable to encrypt data.")(BR-12); failures in UTF-8/Base64 conversion or argument coercion outside that try block propagate unwrapped.
Origin: Steps 4.1–4.3 are implemented in Encrypt a string with DPAPI and executed on behalf of this operation. 5. Write the encrypted Base64 value as the
SAIFAUTHcookie (BR-01, BR-05, BR-06) - 5.1 Create aSetCookieHeaderValue(key, value)withPath = "/"andHttpOnly = true. - 5.2 Render it to a header string with no URL-encoding. - 5.3 Append the string to any existingSet-Cookievalues withStringValues.Concat.Origin: Steps 5.1–5.3 are implemented in Append a raw Set-Cookie header and executed on behalf of this operation.
Process flow¶
The following diagram visualizes this operation's control flow, including the embedded encrypt and header-write sub-operations.
flowchart TD
Start(["Trigger: SetCookie called"]) --> S1["Read HttpContext<br>from accessor"]
S1 --> D1{HttpContext null?}
D1 -->|Yes| ErrNull1([NullReferenceException])
D1 -->|No| S2["Build payload:<br>user + TAB + password + TAB"]
S2 --> S3["Read client remote IP<br>as DPAPI entropy"]
S3 --> D2{RemoteIpAddress null?}
D2 -->|Yes| ErrNull2([NullReferenceException])
D2 -->|No| S4["Encrypt with DPAPI:<br>MachineKey scope + IP entropy"]
S4 --> D3{Encryption failed?}
D3 -->|Yes| ErrEnc(["Exception:<br>unable to encrypt data"])
D3 -->|No| S5["Write Set-Cookie SAIFAUTH<br>header, raw Base64"]
S5 --> EndOk([Set-Cookie header written])
Failure and edge-case behavior¶
- Calling
SetCookieoutside an active HTTP request, or whenRemoteIpAddressis unavailable, throwsNullReferenceExceptionbefore any cookie is written (BR-10) - An exception raised inside the byte-array encrypt call's own try block — including running on a non-Windows host or a non-default Windows installation directory — is wrapped as a generic
System.Exception("DPAPI was unable to encrypt data.")(BR-12, BR-13). UTF-8/Base64 conversion in this operation's string payload handling, and argument coercion that runs before that try block, are not wrapped by this rule. - A tab character embedded in
userorpasswordis not escaped and may corrupt the legacy reader's parsing of the payload (BR-02)
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