Preserve X-Frame-Options if it was already set
This commit is contained in:
parent
6099dfa261
commit
fd81151d31
|
|
@ -248,7 +248,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal
|
||||||
_tokenStore.SaveCookieToken(httpContext, cookieToken);
|
_tokenStore.SaveCookieToken(httpContext, cookieToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_options.SuppressXFrameOptionsHeader)
|
if (!_options.SuppressXFrameOptionsHeader && !httpContext.Response.Headers.ContainsKey("X-Frame-Options"))
|
||||||
{
|
{
|
||||||
// Adding X-Frame-Options header to prevent ClickJacking. See
|
// Adding X-Frame-Options header to prevent ClickJacking. See
|
||||||
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
|
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
|
||||||
|
|
|
||||||
|
|
@ -783,6 +783,31 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal
|
||||||
Times.Never);
|
Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetCookieTokenAndHeader_PreserveXFrameOptionsHeader()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var options = new AntiforgeryOptions();
|
||||||
|
var antiforgeryFeature = new AntiforgeryFeature();
|
||||||
|
var expectedHeaderValue = "DIFFERENTORIGIN";
|
||||||
|
|
||||||
|
// Generate a new cookie.
|
||||||
|
var context = CreateMockContext(
|
||||||
|
options,
|
||||||
|
useOldCookie: false,
|
||||||
|
isOldCookieValid: false,
|
||||||
|
antiforgeryFeature: antiforgeryFeature);
|
||||||
|
var antiforgery = GetAntiforgery(context);
|
||||||
|
context.HttpContext.Response.Headers["X-Frame-Options"] = expectedHeaderValue;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
antiforgery.SetCookieTokenAndHeader(context.HttpContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var xFrameOptions = context.HttpContext.Response.Headers["X-Frame-Options"];
|
||||||
|
Assert.Equal(expectedHeaderValue, xFrameOptions);
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(false, "SAMEORIGIN")]
|
[InlineData(false, "SAMEORIGIN")]
|
||||||
[InlineData(true, null)]
|
[InlineData(true, null)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue