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

Blogging post detail page may have wrong creator authority check. #3098

Closed
gdlcf88 opened this issue Mar 12, 2020 · 1 comment
Closed

Blogging post detail page may have wrong creator authority check. #3098

gdlcf88 opened this issue Mar 12, 2020 · 1 comment

Comments

@gdlcf88
Copy link
Contributor

gdlcf88 commented Mar 12, 2020

private async Task<bool> HasDeletePermission(AuthorizationHandlerContext context, Post resource)
{
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Delete))
{
return true;
}
return false;
}
private async Task<bool> HasUpdatePermission(AuthorizationHandlerContext context, Post resource)
{
if (resource.CreatorId != null && resource.CreatorId == context.User.FindUserId())
{
return true;
}
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Update))
{
return true;
}
return false;
}

private async Task<bool> HasDeletePermission(AuthorizationHandlerContext context, Comment resource)
{
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Delete))
{
return true;
}
return false;
}
private async Task<bool> HasUpdatePermission(AuthorizationHandlerContext context, Comment resource)
{
if (resource.CreatorId != null && resource.CreatorId == context.User.FindUserId())
{
return true;
}
if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Update))
{
return true;
}
return false;
}

It seems that users cannot delete their own posts/comments, but in the detail page I found:

@if (await Authorization.IsGrantedAsync(BloggingPermissions.Posts.Update))
{
<span class="seperator">|</span>
<a asp-page="./Edit" asp-route-postId="@Model.Post.Id" asp-route-blogShortName="@Model.BlogShortName">
<i class="fa fa-pencil"></i> @L["Edit"]
</a>
}
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Posts.Delete) || (CurrentUser.Id == Model.Post.CreatorId))
{
<span class="seperator">|</span>
<a href="#" id="DeletePostLink" data-postid="@Model.Post.Id" data-blogShortName="@Model.BlogShortName">
<i class="fa fa-trash"></i> @L["Delete"]
</a>
}

@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<span class="seperator">|</span>
<a href="#" class="tag deleteLink" data-deleteid="@reply.Id">
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
}

@gdlcf88
Copy link
Contributor Author

gdlcf88 commented Mar 13, 2020

I will close this issue, the problem seems to have been fixed by this commit:
b0adb9f

Hi @yekalkan , maybe this todo needs to be completed:

var hasCommentingPermission = CurrentUser.IsAuthenticated; //TODO: Apply real policy!

@gdlcf88 gdlcf88 closed this as completed Mar 13, 2020
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.

2 participants