Middle · Trace · Forwarded-header trust

Execution context: this is the complete portable .NET9 console companion, using ordinary BCL code. Trace its exact stdout and justify each state or comparison; it does not start the external ASP.NET server or SQL database.

Think through your answer before opening the explanation.

Production engineering

using System;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

var known=System.Net.IPAddress.Parse("203.0.113.10"); foreach(string text in new[]{"127.0.0.1","203.0.113.10"}) { bool trusted=known.Equals(System.Net.IPAddress.Parse(text)); Console.WriteLine(trusted?"https":"http"); }
Reveal answer and reasoning

The output lines, in order, are “http”; “https”. The portable .NET9 console companion parses one known IP address and compares two fixed offered addresses with it. Loopback is not equal to the configured documentation address, so the first line is http. The matching address produces https on the second line. These outputs are chosen by the local trust-policy comparison. There is no forwarded-header parser, middleware pipeline, socket or TLS handshake in this program.

Actual IPAddress objects are used for equality rather than comparing arbitrary strings, but the example remains only a bounded policy observation. It cannot establish which network route a real request followed.

A trusted header stating https describes the claimed original request scheme; the connection to this test server is still plain loopback HTTP. A forwarded client address likewise does not authenticate the user behind it. Real deployments also need to know whether the proxy overwrites or appends incoming header values and which hop is immediately connected. Clearing every trust restriction without adding the intended peer would create a materially different policy.

Host filtering, TLS termination, application identity and resource authorization remain separate controls. The known address comparison and one-hop limit do not establish those additional guarantees automatically.

What a strong answer covers

  • Exact output: http | https
  • The portable .NET9 console companion parses one known IP address and compares two fixed offered addresses with it.
  • A trusted header stating https describes the claimed original request scheme; the connection to this test server is still plain loopback HTTP.

Common pitfall

A trusted header stating https describes the claimed original request scheme; the connection to this test server is still plain loopback HTTP. A forwarded client address likewise does not authenticate the user behind it. Real deployments also need to know whether the proxy overwrites or appends incoming header values and which hop is immediately connected. Clearing every trust restriction without adding the intended peer would create a materially different policy. Host filtering, TLS termination, application identity and resource authorization remain separate controls. The known address comparison and one-hop limit do not establish those additional guarantees automatically.

Follow-up questions

  1. Why would enabling X-Forwarded-Host require another host-policy review even when X-Forwarded-Proto was already tested?
  2. Which actual transport segment remains plain HTTP after forwarded scheme metadata becomes https?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions