Skip to content

Commit

Permalink
Prevent anonymous users performing GET on contentitem api (#5753)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlwoodhouse authored Mar 19, 2020
1 parent 0872a9a commit d5ff090
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public async Task<IActionResult> Get(string contentItemId)
return NotFound();
}

if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
if (!await _authorizationService.AuthorizeAsync(User, Permissions.GetApiContent) ||
!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
{
return this.ChallengeOrForbid();
}
Expand Down
14 changes: 8 additions & 6 deletions src/OrchardCore.Modules/OrchardCore.Contents/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Permissions : IPermissionProvider
public static readonly Permission PreviewOwnContent = CommonPermissions.PreviewOwnContent;
public static readonly Permission CloneContent = CommonPermissions.CloneContent;
public static readonly Permission CloneOwnContent = CommonPermissions.CloneOwnContent;
public static readonly Permission GetApiContent = new Permission("GetApiContent", "View content via the api");

//public static readonly Permission MetaListContent = new Permission { ImpliedBy = new[] { EditOwnContent, PublishOwnContent, DeleteOwnContent } };

Expand All @@ -42,7 +43,8 @@ public Task<IEnumerable<Permission>> GetPermissionsAsync()
PreviewOwnContent,
PreviewContent,
CloneContent,
CloneOwnContent
CloneOwnContent,
GetApiContent
}
.AsEnumerable());
}
Expand All @@ -52,26 +54,26 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
return new[] {
new PermissionStereotype {
Name = "Administrator",
Permissions = new[] {PublishContent, EditContent, DeleteContent, PreviewContent, CloneContent}
Permissions = new[] {PublishContent, EditContent, DeleteContent, PreviewContent, CloneContent, GetApiContent}
},
new PermissionStereotype {
Name = "Editor",
Permissions = new[] {PublishContent, EditContent, DeleteContent, PreviewContent, CloneContent}
Permissions = new[] {PublishContent, EditContent, DeleteContent, PreviewContent, CloneContent, GetApiContent }
},
new PermissionStereotype {
Name = "Moderator"
},
new PermissionStereotype {
Name = "Author",
Permissions = new[] {PublishOwnContent, EditOwnContent, DeleteOwnContent, PreviewOwnContent, CloneOwnContent}
Permissions = new[] {PublishOwnContent, EditOwnContent, DeleteOwnContent, PreviewOwnContent, CloneOwnContent, GetApiContent }
},
new PermissionStereotype {
Name = "Contributor",
Permissions = new[] {EditOwnContent, PreviewOwnContent, CloneOwnContent}
Permissions = new[] {EditOwnContent, PreviewOwnContent, CloneOwnContent, GetApiContent }
},
new PermissionStereotype {
Name = "Authenticated",
Permissions = new[] {ViewContent}
Permissions = new[] {ViewContent, GetApiContent }
},
new PermissionStereotype {
Name = "Anonymous",
Expand Down

0 comments on commit d5ff090

Please sign in to comment.