Skip to content

Handling authZ for READ operation with no fields referenced in url#953

Merged
ayush3797 merged 7 commits into
mainfrom
dev/agarwalayush/removeRedundantCodePath
Nov 11, 2022
Merged

Handling authZ for READ operation with no fields referenced in url#953
ayush3797 merged 7 commits into
mainfrom
dev/agarwalayush/removeRedundantCodePath

Conversation

@ayush3797

@ayush3797 ayush3797 commented Nov 7, 2022

Copy link
Copy Markdown
Contributor

Why make this change?

Fixes #487.

Context:
This fix takes care of one special case where let's say we have a entity Book in which the READ operation has no column exposed i.e. include = [], or more generally when no field is exposed for READ operation on the entity.
In such a case, when the DAB engine receives a READ request where the url does not contain any key and there are no other clauses like order by/select/filter etc. (eg. the url is https://localhost:5001/api/Book/), all the authorization checks would pass. This is the only case when we would hit the code block in question in this issue here. This however is an invalid case, where the user is not authorized to access any field for the READ operation on the entity and should be failed at the authorization stage itself. The changes in the PR do exactly that.

What is this change?

  1. Removed incorrect code block here.
    What the code block used to do?
    In case when the Columns.Count == 0 (where Columns is the list of columns which the query selects), this code block used to add all the fields present in the Entity to the Columns list, which should not be done because if the Columns.Count ==0 at that stage, the user is not authorised to access any field in the entity for the READ operation.
    We should fail such a request in the authorization stage itself.
  2. To fail the request in authorization stage, adding additional during column authorization check for READ operation : When OperationMetaData.AllowedExposedColumns.Count() ==0 => The user is not authorized to access any field in the entity for this operation. We thus fail the request.

Example Request to see the issue:

  1. Set permission for an READ operation entity lets say Book to have no columns exposed.
  2. Execute a GET request with url : https://localhost:5001/api/Book/. It would return all the rows in the books table with all the fields. However since no fields were exposed, the user was not authorized to see any of them, and hence the behavior is incorrect.

@ayush3797 ayush3797 changed the title Handling READ operation with no fields referenced in url Handling authN for READ operation with no fields referenced in url Nov 7, 2022
@ayush3797 ayush3797 self-assigned this Nov 7, 2022
@ayush3797 ayush3797 added rest auth bug Something isn't working labels Nov 7, 2022
@ayush3797 ayush3797 marked this pull request as ready for review November 7, 2022 10:32
@ayush3797 ayush3797 changed the title Handling authN for READ operation with no fields referenced in url Handling authZ for READ operation with no fields referenced in url Nov 7, 2022
@jarupatj

jarupatj commented Nov 7, 2022

Copy link
Copy Markdown
Contributor

Do we have a test for this?

@seantleonard

Copy link
Copy Markdown
Contributor

While the link to the separate issue is good, it would be beneficial to give brief summary here to reduce the need cross reference across issue/PR what is done here.

I don't follow this, can you describe behavior before/after this change and list some sample requests?

Adding additional during column authorization check for READ operation : When OperationMetaData.AllowedExposedColumns.Count() ==0 => The user is not authorized to access any field in the entity for this operation. We fail such a request.

It would be helpful to provide context, especially for other reviewers about why the removed code block was redundant/what that code block was:

Removed redundant code block.

@ayush3797

Copy link
Copy Markdown
Contributor Author

While the link to the separate issue is good, it would be beneficial to give brief summary here to reduce the need cross reference across issue/PR what is done here.

I don't follow this, can you describe behavior before/after this change and list some sample requests?

Adding additional during column authorization check for READ operation : When OperationMetaData.AllowedExposedColumns.Count() ==0 => The user is not authorized to access any field in the entity for this operation. We fail such a request.

It would be helpful to provide context, especially for other reviewers about why the removed code block was redundant/what that code block was:

Removed redundant code block.

Addressed your concerns in the PR description. Please have a look.

@ayush3797

Copy link
Copy Markdown
Contributor Author

Do we have a test for this?

Yep, in progress.

Comment thread src/Service.Tests/Authorization/REST/RestAuthorizationHandlerUnitTests.cs Outdated

@Aniruddh25 Aniruddh25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread src/Service.Tests/Authorization/REST/RestAuthorizationHandlerUnitTests.cs Outdated

@severussundar severussundar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@ayush3797 ayush3797 merged commit 1b2bb0e into main Nov 11, 2022
@ayush3797 ayush3797 deleted the dev/agarwalayush/removeRedundantCodePath branch November 11, 2022 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth bug Something isn't working rest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Unused code path in SqlQueryStructure

5 participants