Skip to content

Commit 11a9624

Browse files
chekm8dougbu
authored andcommitted
Correcting multiple X-Frame-Options header (#50)
- #7 * According to RFC7034, only these three values, DENY, SAMEORIGIN and ALLOW FROM are valid values and they are mutually exclusive; that is, the header field must be set to exactly ONE of these three values. This will prevent the CSRF code from inserting it multiple times as well as duplicating it if it was already set elsewhere (e.g. IIS Header) * Changed var to const string per request. * Changed const name to avoid SA130 error * Changing to correct cost naming per standard
1 parent 55c9d83 commit 11a9624

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/System.Web.WebPages/Helpers/AntiXsrf/AntiForgeryWorker.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ public TagBuilder GetFormInputElement(HttpContextBase httpContext)
104104
// Adding X-Frame-Options header to prevent ClickJacking. See
105105
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
106106
// for more information.
107-
httpContext.Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
107+
const string FrameHeaderName = "X-Frame-Options";
108+
if (httpContext.Response.Headers[FrameHeaderName] == null)
109+
{
110+
httpContext.Response.AddHeader(FrameHeaderName, "SAMEORIGIN");
111+
}
108112
}
109113

110114
// <input type="hidden" name="__AntiForgeryToken" value="..." />
@@ -181,4 +185,4 @@ public void Validate(HttpContextBase httpContext, string cookieToken, string for
181185
_validator.ValidateTokens(httpContext, ExtractIdentity(httpContext), deserializedCookieToken, deserializedFormToken);
182186
}
183187
}
184-
}
188+
}

0 commit comments

Comments
 (0)