Skip to content
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

Look into: RequireAntiForgeryCheck: false #103

Closed
brockallen opened this issue Jun 20, 2022 · 11 comments · Fixed by #107
Closed

Look into: RequireAntiForgeryCheck: false #103

brockallen opened this issue Jun 20, 2022 · 11 comments · Fixed by #107

Comments

@brockallen
Copy link
Member

With this fix the RequireAntiForgeryCheck: false stopped working for the local API when set at the controller action level attribute like this:

// GET productapi/v1/image/5
[BffApi(false)]
[HttpGet("{id:length(24)}")]
public Task<ActionResult> Get(string id) => (

It now requires the anti-forgery header for this action and returns 401. If rollback to 1.2.1 it works as expected.

Originally posted by @dgrozenok in #102 (comment)

@brockallen
Copy link
Member Author

Also, it would help to have more automated tests around the various attributes at the various levels.

@brockallen
Copy link
Member Author

Hmm.. so I did some digging and I found an odd behavior: GetOrderedMetadata does not return attributes in the order I would have expected. The order is: 1) controller, 2) action, 3) route. This is different from how MVC used to work. In any event, it doesn't matter if we use GetOrderedMetadata or GetMetadata, since they work the same (in essence). So I think more investigation is in order.

@ArturDorochowicz -- interesting info for you.

@dgrozenok
Copy link

In addition to the action attribute BffApi(false) I also have this in the Startup class:

app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers()
                .RequireAuthorization("ApiScope")
                .AsBffApiEndpoint();

@ArturDorochowicz
Copy link
Contributor

ArturDorochowicz commented Jun 21, 2022 via email

@brockallen
Copy link
Member Author

BFF used the least important metadata

Perhaps some of the confusion is the definition of this. Our assumption was that the order was at the route config (in startup), then controller, then action. And to me the action is most important. But of course, this issue has raise the fact that there is no hierarchy and instead it's just a flat list. This makes me wonder why there's an API called GetOrderedMetadata at all if it's just a flat list. I suspect someone thinks there's an order, but is that documented? Based on the order I see, it's not intuitive so it needs formal docs.

In any event -- we are going to roll back the patch given that our assumptions were incorrect. We will then address your issue @ArturDorochowicz with a v2.0 because we expect that it will require a breaking change.

@ArturDorochowicz
Copy link
Contributor

ArturDorochowicz commented Jun 21, 2022 via email

@leastprivilege
Copy link
Member

OK - sorry for the confusion. We will roll-back the change and re-design this feature.

@dgrozenok
Copy link

Interesting. I didn't realize the configuration of an endpoint is at the same level as the action. I do agree though that from the user of the package standpoint I would prefer the mvc global filter-like behavior with the hierarchy starting from the Startup, then controller, and the action being the most specific.

@leastprivilege
Copy link
Member

Agreed. The plan is to change the behavior so it is inline with RequireAuthorization, [Authorize] and [AllowAnonymous].

That should feel more predictable for most people.

@brockallen
Copy link
Member Author

I do agree though that from the user of the package standpoint I would prefer the mvc global filter-like behavior with the hierarchy starting from the Startup, then controller, and the action being the most specific.

Yes, and given that attributes added to the route show up as action-level shows that this implementation detail is not well understood, so we're going to need to take the [AllowAnonymous] approach (given that they're all essentially flat).

@brockallen
Copy link
Member Author

Also, it would help to have more automated tests around the various attributes at the various levels.

Looks like we already had tests for the non-YARP anti-xsrf.

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

Successfully merging a pull request may close this issue.

4 participants