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

Improved Permissions: Set purchase cost to null if user has no permission to view the price #15936

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

casdr
Copy link

@casdr casdr commented Dec 9, 2024

Description

We want to give customers access to view all assets that belong to their company. While the current view_purchase_cost permission hides this value at the self-assigned assets view, it's still visible in other views.

When getPurchaseCostAttribute is implemented this way, it hides the purchase cost for all types of assets for users that do not have this permission.

Example (as VIP user):

image

Example (as customer user):

image

This also ensures this data isn't leaked through API/AJAX calls.

I wasn't able to find a related existing issue for this PR.

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Ran all unit tests
  • Tested the implementation by creating a user that doesn't have the permission to view the purchase cost

Test Configuration:

  • PHP version: 8.2.26
  • MySQL version: MariaDB 11.5.2
  • Webserver version: Apache/2.4.62
  • OS version: Alphine Linux 3.19.4

Checklist:

@casdr casdr requested a review from snipe as a code owner December 9, 2024 13:16
Copy link

welcome bot commented Dec 9, 2024

💖 Thanks for this pull request! 💖

We use semantic commit messages to streamline the release process and easily generate changelogs between versions. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix if it doesn't have one already.

Examples of commit messages with semantic prefixes:

  • Fixed #<issue number>: don't overwrite prevent_default if default wasn't prevented
  • Added #<issue number>: add checkout functionality to assets
  • Improved Asset Checkout: use new notification method for checkout

Things that will help get your PR across the finish line:

  • Document any user-facing changes you've made.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

Copy link

what-the-diff bot commented Dec 9, 2024

PR Summary

  • Improved Security Features in SnipeModel Class
    To bolster the security of our system, we've implemented an 'Auth' tool in the 'SnipeModel' class. This is a piece of program responsible for managing items in our application.

  • Introduced Permission-based Item Cost View
    We have created a new function named 'getPurchaseCostAttribute'. This function is responsible for managing the visibility of an item's purchase cost, based on the user's access permissions.

  • Filtered Purchase Cost Viewability
    Any user who is either not signed into the system or does not have the specific permission called 'self.view_purchase_cost', will not have access to view the purchase cost details of an item - the system will display this as 'null', signifying no data available.

@casdr casdr changed the title Cdr/disable purchase cost if no access Permissions: Set purchase cost to null if user has no permission to view the price Dec 9, 2024
@casdr
Copy link
Author

casdr commented Dec 9, 2024

Let me know if this fix is okay for this issue. I can also imagine you want to implement this on the presentation logic, my idea doing it this way was to ensure we wouldn't miss a spot where this check should be implemented.

@snipe
Copy link
Owner

snipe commented Dec 9, 2024

Hi - thanks for this PR! All PRs should be targeted towards the develop branch, per our dev docs - also, we don't have that permission in the first place. The self permission deals only with a user's ability to see details about things assigned to them (via the Account > View Assigned Assets menu item), while your screenshot is from the POV of a user who has the ability to see assets in general.

@casdr
Copy link
Author

casdr commented Dec 9, 2024

@snipe good point. I'll add the permission and use the correct base branch.

@casdr casdr marked this pull request as draft December 10, 2024 12:55
@casdr casdr marked this pull request as ready for review January 3, 2025 09:00
@casdr casdr marked this pull request as draft January 3, 2025 09:00
@casdr casdr changed the base branch from master to develop January 3, 2025 09:00
@casdr casdr marked this pull request as ready for review January 3, 2025 09:01
@casdr casdr changed the title Permissions: Set purchase cost to null if user has no permission to view the price Improved Permissions: Set purchase cost to null if user has no permission to view the price Jan 3, 2025
@snipe
Copy link
Owner

snipe commented Jan 6, 2025

I guess I'm just not really clear on the use-case here. If you have the ability to view an asset's history, when would you not be able to view the price of assets not assigned to you. We hide that for assets assigned to the user (via the Assigned Assets section), but it's hard for me to imagine a situation where someone who can view asset details for items not checked out just to them shouldn't be able to see it. Additionally, this presents opportunities for data leakage (for example in the asset's history, if the price was changed from null to a specific value, that change would show in asset history.)

@casdr
Copy link
Author

casdr commented Jan 6, 2025

About the use-case:

We want to give some customers access to our Snipe-IT instance. These customers can view all the assets that have been assigned to their company, including those checked out to a location instead of a user, but we don't want them to see the purchase cost. These assets will not show up in the Assigned Assets section.

The data leakage on the history page is an interesting note. If you're open to eventually merging this, I'll look into this as well.

I've also joined Discord if you want to discuss this further over chat.

@snipe
Copy link
Owner

snipe commented Jan 7, 2025

but we don't want them to see the purchase cost.

That's the use-case I'm referring to - what would be the reason for them being able to view all of the other data on an asset but not the cost?

@casdr
Copy link
Author

casdr commented Jan 8, 2025

what would be the reason for them being able to view all of the other data on an asset but not the cost?

Customers buy these assets from us with a margin. Snipe-IT is primarily used by our colleagues internally and we fill the purchase cost from our vendor. The purchase cost for the customer is different from this price, so we want to hide this field for the customers that have access to Snipe-IT.

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

Successfully merging this pull request may close these issues.

2 participants