Skip to content

Correcting multiple X-Frame-Options header #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 21, 2017
Merged

Conversation

chekm8
Copy link
Contributor

@chekm8 chekm8 commented Jun 19, 2017

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)

Addresses #7

…LLOW 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)
@dnfclas
Copy link

dnfclas commented Jun 19, 2017

@chekm8,
Thanks for having already signed the Contribution License Agreement. Your agreement has not been validated yet. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@chekm8
Copy link
Contributor Author

chekm8 commented Jun 28, 2017

I was just checking back to see if there was anything additional I had to do for the pull to be reviewed/accepted. This is my first contribution and I believe the license agreement was completed successfully.
Looking forward to this fix being incorporated, Thanks!

@@ -104,7 +104,11 @@ public TagBuilder GetFormInputElement(HttpContextBase httpContext)
// Adding X-Frame-Options header to prevent ClickJacking. See
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
// for more information.
httpContext.Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead just be changed to:

httpContext.Response.Headers.Set("X-Frame-Options", "SAMEORIGIN");

This would make sure that anti-forgery gets the header it wants by overwriting any existing value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting back to me Eilon. The "If"/Add check was to ensure that say if an administrator in IIS forced this header to a setting other than SAMEORIGIN (e.g. DENY or ALLOW FROM) it would allow them to. If you always just set it to SAMEORIGIN you are not giving the admin the option to override it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just checking back in, does the above comment make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this makes sense. I guess it's debatable which one should win over the other but I don't feel strongly about that, so this should be fine.

@Eilon
Copy link
Contributor

Eilon commented Sep 15, 2017

BTW sorry for the long delay on this! I got sent some reminders from a couple of colleagues to get back to you on this.

@Eilon
Copy link
Contributor

Eilon commented Sep 21, 2017

@dougbu can you do an extra review and merge when ready?

@@ -104,7 +104,11 @@ public TagBuilder GetFormInputElement(HttpContextBase httpContext)
// Adding X-Frame-Options header to prevent ClickJacking. See
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
// for more information.
httpContext.Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
var xFrameHeaderName = "X-Frame-Options";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually one tiny comment: this should be a const string because it's not really a variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also rename this const because the command-line build hits an FxCop error:

SA130: The variable name 'xFrameHeaderName' begins with a prefix that looks like Hungarian notation. Remove the prefix or add it to the list of allowed prefixes.

Copy link
Contributor

@dougbu dougbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chekm8 please let me know if you aren't free to make the change @Eilon requested. In that case, I'll merge your commit and follow-up with a quick fix-up. (But, it's cleaner to do a 4-line change in one commit 😸

@@ -104,7 +104,11 @@ public TagBuilder GetFormInputElement(HttpContextBase httpContext)
// Adding X-Frame-Options header to prevent ClickJacking. See
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
// for more information.
httpContext.Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
const string xFrameHeaderName = "X-Frame-Options";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name will still fail a build with the SA130 error. (Might be worth setting up AppVeyor for this repo.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dougbu I uploaded the string const change to my repo, Do I need to initiate another pull request or anything?

Do you need further changes to get past the SA130 error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please renamed the const to something like frameHeader or frameHeaderName. That'll get command-line builds working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All set, let me know if you need anything else. Thanks.

@@ -104,7 +104,11 @@ public TagBuilder GetFormInputElement(HttpContextBase httpContext)
// Adding X-Frame-Options header to prevent ClickJacking. See
// http://tools.ietf.org/html/draft-ietf-websec-x-frame-options-10
// for more information.
httpContext.Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
const string frameHeaderName = "X-Frame-Options";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoot. Command-line build now fails with

SA1303: Constants must start with an upper-case letter: frameHeaderName.

Please rename this again -- FrameHeaderName. (I wasn't aware this error was enabled.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about now :)

@dougbu dougbu merged commit 11a9624 into aspnet:master Sep 21, 2017
@chekm8
Copy link
Contributor Author

chekm8 commented Sep 22, 2017

@dougbu Thanks, I know I can grab a nightly build but, do you guy have a estimated timeline for your next RTM release and nuget package build? I'm not really sure how that process works.

@dougbu
Copy link
Contributor

dougbu commented Sep 22, 2017

@chekm8 the best place to see the future is https://github.com/aspnet/Home/wiki/Roadmap

The page needs a refresh now that 2.0.0 is out. But, I recommend checking there occasionally for more detail on 2.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants