{"record":{"id":"3bb37544a3297676","repo":"dotnet/yarp","slug":"unexpected-value-for-forwarded-token-expected","errorCode":null,"errorMessage":"Unexpected value for Forwarded: {token}. Expected 'for', 'host', 'proto', or 'by'","messagePattern":"Unexpected value for Forwarded: (.+?)\\. Expected 'for', 'host', 'proto', or 'by'","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ReverseProxy/Transforms/ForwardedTransformFactory.cs","lineNumber":222,"sourceCode":"                    useFor = true;\n                    forFormat = NodeFormat.Random; // RFC Default\n                }\n                else if (string.Equals(token, ByKey, StringComparison.OrdinalIgnoreCase))\n                {\n                    useBy = true;\n                    byFormat = NodeFormat.Random; // RFC Default\n                }\n                else if (string.Equals(token, HostKey, StringComparison.OrdinalIgnoreCase))\n                {\n                    useHost = true;\n                }\n                else if (string.Equals(token, ProtoKey, StringComparison.OrdinalIgnoreCase))\n                {\n                    useProto = true;\n                }\n                else\n                {\n                    throw new ArgumentException($\"Unexpected value for Forwarded: {token}. Expected 'for', 'host', 'proto', or 'by'\");\n                }\n            }\n\n            var expected = 1;\n\n            var headerAction = ForwardedTransformActions.Set;\n            if (transformValues.TryGetValue(ActionKey, out headerValue))\n            {\n                expected++;\n                headerAction = Enum.Parse<ForwardedTransformActions>(headerValue);\n            }\n\n            if (useFor && transformValues.TryGetValue(ForFormatKey, out var forFormatString))\n            {\n                expected++;\n                forFormat = Enum.Parse<NodeFormat>(forFormatString, ignoreCase: true);\n            }\n","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Transforms/ForwardedTransformFactory.cs#L204-L240","documentation":"Thrown by ForwardedTransformFactory when parsing the `Forwarded` transform's spec list and encountering a token that is not `for`, `host`, `proto`, or `by` (case-insensitive). The Forwarded transform (RFC 7239) only emits those four fields, so any other token is invalid.","triggerScenarios":"Config sets the Forwarded transform with an unknown field token, e.g. `Forwarded: user,for` or a typo like `fro` instead of `for`.","commonSituations":"Confusing the RFC 7239 Forwarded fields with X-Forwarded-* field names. Typo in a token. Copying an example that used a non-standard extension.","solutions":["Use only the supported tokens: `for`, `host`, `proto`, `by` (case-insensitive, comma-separated).","If you need a custom field, use a custom RequestHeader transform instead.","Re-read the Forwarded transform docs and align the spec string."],"exampleFix":"// before\n{ \"Forwarded\": \"fro,host\" }\n// after\n{ \"Forwarded\": \"for,host,proto\" }","handlingStrategy":"validation","validationCode":"var allowed = new[] { \"for\", \"host\", \"proto\", \"by\" };\nforeach (var token in spec.Split(','))\n    if (!allowed.Contains(token, StringComparer.OrdinalIgnoreCase)) throw new ArgumentException($\"Bad Forwarded token: {token}\");","typeGuard":"static bool IsValidForwardedSpec(string spec) =>\n    spec.Split(',').All(t => new[]{\"for\",\"host\",\"proto\",\"by\"}.Contains(t.Trim(), StringComparer.OrdinalIgnoreCase));","tryCatchPattern":null,"preventionTips":["Restrict Forwarded tokens to for/host/proto/by.","Do not confuse X-Forwarded-* names with RFC 7239 field names.","Validate the spec string in config tests."],"tags":["transforms","forwarded","config","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}