Skip to content

Authorization broken in Razor Pages .Net Core 3.0 preview 3 #8387

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

Closed
Ponant opened this issue Mar 10, 2019 · 10 comments
Closed

Authorization broken in Razor Pages .Net Core 3.0 preview 3 #8387

Ponant opened this issue Mar 10, 2019 · 10 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates blocked The work on this issue is blocked due to some dependency bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@Ponant
Copy link
Contributor

Ponant commented Mar 10, 2019

Asp.Net Core Identity 3.0 Preview 3 template with RP
Authorize attribute does nothing on the Privacy page
AuthorizePage nothing
AuthorizeFolder nothing

You can also navigate to /Identity/Account/Manage, which should trigger back to login whereas it shows Unable to load user with ID '' gotten from the get request.
Is this planned for preview 4?
Related to #7011 which is flagged as done and closed but does not work.

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 10, 2019
@Eilon
Copy link
Contributor

Eilon commented Mar 10, 2019

@Ponant can you show exactly what modifications you made to the app after the initial project was created?

@Ponant
Copy link
Contributor Author

Ponant commented Mar 11, 2019

@Eilon , go to the Identity/Account/Manage page of the template; there is no need to change anything to the template to get this bug.
Otherwise, you can do this

    [Authorize]
    public class PrivacyModel : PageModel

but you will be able to access the Privacy page

Also

 services.AddMvc().AddRazorPagesOptions(o=>o.Conventions.AuthorizePage("/Privacy"))
                .AddNewtonsoftJson();

does nothing.
Same for AuthorizeFolder. I did not test further as there is clearly a huge hole while the issue is absent in 2.2.

@Eilon
Copy link
Contributor

Eilon commented Mar 11, 2019

@javiercn / @pranavkm - any idea?

@javiercn
Copy link
Member

Not sure what's happening here, but I'll take a look.

@Ponant
Copy link
Contributor Author

Ponant commented Mar 11, 2019

Just create the identity template and navigate to identity/account/manage and you should see it traversing the get request whereas it requires authorization. You can also use the AuthorizePage and the like and it should just ignore them. Let me know if you can reproduce. Cheers

@mkArtak
Copy link
Contributor

mkArtak commented Mar 13, 2019

Thanks for the details, @Ponant.
I could repro this using Preview3 bits.
This is where the failure is coming from: https://github.com/aspnet/AspNetCore/blob/c95ee2b051814b787b07f55ff224d03d550aafeb/src/Identity/samples/IdentitySample.DefaultUI/Areas/Identity/Pages/Account/Manage/Index.cshtml.cs#L68
Obviously, the expectation here is that the user should be known. So indeed, authorization was completely bypassed.

@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. 1 - Ready labels Mar 13, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview4 milestone Mar 13, 2019
@Ponant
Copy link
Contributor Author

Ponant commented Mar 13, 2019

@mkArtak , out of curiosity, do you know from where the bug comes from?

@mkArtak
Copy link
Contributor

mkArtak commented Mar 14, 2019

Not really, @Ponant. Let's wait for @pranavkm to handle this - he'll do a great job here.

@rynowak
Copy link
Member

rynowak commented Mar 24, 2019

The root cause of this issue is that the methods like AuthorizePage create an AuthorizeFilter but we also need an IAuthorizeData to show up in the endpoint metadata.

Since AuthorizeFilter is an MVC feature, it won't get executed by the authorization middleware - however the authorization middleware will run and suppress the filter.

We had a test gap in this area due to some functional tests that weren't running in the correct configuration. Updating the test app setup to be more like our documentation caused these tests to fail. I plan to check in the changes to the test setup as part of some other changes and skip the tests related to this issue.

To be crystal clear on the point - this is is a bug, and it is broken in preview 3. Official releases such as 2.2 do not have this bug.

@pranavkm pranavkm added Done This issue has been fixed and removed 2 - Working labels Apr 8, 2019
pranavkm added a commit that referenced this issue Apr 8, 2019
* Make AuthorizeFilter work in endpoint routing

Fixes #8387
@Ponant
Copy link
Contributor Author

Ponant commented Apr 9, 2019

@pranavkm , is it possible to know the cause of the bug? Thanks for the fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates blocked The work on this issue is blocked due to some dependency bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests

7 participants