Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

AntiForgery Interfaces. #180

Closed
wants to merge 7 commits into from
Closed

AntiForgery Interfaces. #180

wants to merge 7 commits into from

Conversation

harshgMSFT
Copy link
Contributor

No description provided.

private static readonly AntiForgeryWorker _worker = CreateSingletonAntiForgeryWorker();
private static readonly string _purpose = "Microsoft.AspNet.Mvc.AntiXsrf.AntiForgeryToken.v1" ;

private static AntiForgeryWorker CreateSingletonAntiForgeryWorker()
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine these would come from the DI and we'd register this as a singleton in the DI rather than have statics here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup there is a todo for it

Copy link
Contributor

Choose a reason for hiding this comment

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

This should go in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@harshgMSFT could you summarize what will be placed in DI and the scenarios where users would override our default implementations?

@dougbu
Copy link
Contributor

dougbu commented Apr 4, 2014

current code doesn't contain any virtual methods, making it difficult to see what classes users may derive from when implementing the interfaces. complete replacements and slight tweaks are both cases we should support.

@harshgMSFT
Copy link
Contributor Author

@dougbu .. We discussed and we thought it is better for the class to remain a sealed class, and not be introduced in the DI System. The only scenarios where people want extensibility, is
a. When people want to use their own claim types and extract the claim id.
b. On top of what the AF system does provide an additional check ( a good example would be to check the timestamp on the cookie and expire it if needed). These scenarios can be met by IAdditionalDataProvider.
c. If an advanced user does want to replace the entire AF system, he /she can change the entry point by simply adding a new HTMLHelper which calls into their implementation.

Also contains some code ported over.
This Commit is only for review purpose.

public AntiForgeryToken GetFormToken(HttpContext httpContext)
{
string value = httpContext.Request.GetFormAsync().Result[_config.FormFieldName];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't block while reading the form.

Remaining:
		1. Generate the AntiForgeryCookieName.
		2. Update the ClaimsUidExtractor.
@davidfowl davidfowl added this to the Post Alpha milestone Apr 16, 2014
{
public sealed class AntiForgeryConfigWrapper : IAntiForgeryConfig
{
public IAntiForgeryAdditionalDataProvider AdditionalDataProvider
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this just a service?

@harshgMSFT
Copy link
Contributor Author

@GrabYourPitchforks BranchUpdated.

/// <param name="context">The http context associated with the current call.</param>
/// <param name="cookieToken">The token that was supplied in the request cookie.</param>
/// <param name="formToken">The token that was supplied in the request form body.</param>
[EditorBrowsable(EditorBrowsableState.Advanced)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding these attributes, they should generally be avoided and there has to be a really good reason do add them (which I've yet to ever see except for Obsoleted methods)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine removing these. We can always go back during API reviews and add these back (if at all).

/// <param name="oldCookieToken">The anti-forgery token - if any - that already existed
/// for this request. May be null. The anti-forgery system will try to reuse this cookie
/// value when generating a matching form token.</param>
/// </remarks>
Copy link
Contributor

Choose a reason for hiding this comment

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

where is the opening of the tag

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 catching that!

/// <returns>An HTML string corresponding to an &lt;input type="hidden"&gt;
/// element. This element should be put inside a &lt;form&gt;.</returns>
/// <remarks>
/// This method has a side effect: A response cookie is set if there is no valid cookie associated with the request.
Copy link
Contributor

Choose a reason for hiding this comment

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

line length.

Generally if there is a scroll bar when you set up the PR, I'm going to go and comment on it.

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

Successfully merging this pull request may close these issues.

7 participants