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

Fixed #11794 Admins Cannot View Encrypted Field #13295

Merged

Conversation

inietov
Copy link
Collaborator

@inietov inietov commented Jul 11, 2023

Description

Add permission to 'admin' roles to see encrypted fields values when looking for an asset (AssetsTransformer), and when viewing the details of a determined asset (resources/views/hardware/view.blade.php).

Fixes #11794

Type of change

  • [x} Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Test Configuration:

  • PHP version: 8.1
  • MySQL version: 8.0.23
  • Webserver version: PHP dev server
  • OS version: Debian 11

@what-the-diff
Copy link

what-the-diff bot commented Jul 11, 2023

PR Summary

  • Enhanced Security Checks in AssetsTransformer.php
    The transformAsset function now checks for both 'admin' and 'superadmin' user roles. This provides an additional layer of security, ensuring only privileged users have access to decrypted values. Should a field be formatted as 'DATE', the decrypted value will also be neatly formatted as a date if the user carries the 'admin' role.

  • Role Permissions Update in view.blade.php
    Permissions directives have been updated, replacing @can with the @canany directive. Now the 'admin' role is included alongside the 'superuser' role. This will allow more types of users to engage with the app functionality, broadening the use-case scenarios without compromising security.

@snipe
Copy link
Owner

snipe commented Jul 12, 2023

My expectation here would be that if you have the ability to edit an asset (and therefore edit the encrypted custom field) you should be able to see the value of that field.

@inietov
Copy link
Collaborator Author

inietov commented Jul 14, 2023

@snipe So instead of looking the roles I should look for the correct permissions? or in addition to the roles I need to check permissions?

@snipe
Copy link
Owner

snipe commented Jul 19, 2023

@snipe So instead of looking the roles I should look for the correct permissions? or in addition to the roles I need to check permissions?

That's an excellent question.

Right now it looks like only superusers can view encrypted custom fields. Right now it looks like only superusers can see encrypted custom fields in the list view and detail view, but it doesn't look like we check for a gate on the edit screen - which is exactly what the OP was reporting.

<div id='custom_fields_content'>
<!-- Custom Fields -->
@if ($item->model && $item->model->fieldset)
<?php $model = $item->model; ?>
@endif
@if (Request::old('model_id'))
@php
$model = \App\Models\AssetModel::find(old('model_id'));
@endphp
@elseif (isset($selected_model))
@php
$model = $selected_model;
@endphp
@endif
@if (isset($model) && $model)
@include("models/custom_fields_form",["model" => $model])
@endif
</div>

The problem here is that we're being inconsistent with the gating. If only superusers should be able to see encrypted custom fields in a list view or detail view, they should be the only ones that can edit them as well. However, this will likely break existing functionality.

We do check for that gate in the API responses:

$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));

Stupidly, we check for admin permissions on the edit screen, so it seems we have 3 problems now.

@if (($field->field_encrypted=='0') || (Gate::allows('admin')))
<input type="text" value="{{ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}" id="{{ $field->db_column_name() }}" class="form-control" name="{{ $field->db_column_name() }}" placeholder="Enter {{ strtolower($field->format) }} text">
@else
<input type="text" value="{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}" class="form-control disabled" disabled>
@endif

Maybe we should add "view/edit encrypted fields" as an asset permission? It would mean a larger changeset but might be worth considering. My concern would potentially be that if ONLY superusers could see this before, it could potentially create a privilege escalation issue. Meaning, a "regular user" who is allowed to manage users but is not a superadmin could potentially allow asset managers who are not super admins to see data they previously could not. 🤔

Screenshot 2023-07-19 at 1 40 35 PM

@if ($field->isFieldDecryptable($asset->{$field->db_column_name()} ))
@can('superuser')
@if (($field->format=='URL') && ($asset->{$field->db_column_name()}!=''))
<a href="{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}" target="_new">{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}</a>
@elseif (($field->format=='DATE') && ($asset->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::gracefulDecrypt($field, \App\Helpers\Helper::getFormattedDateObject($asset->{$field->db_column_name()}, 'date', false)) }}
@else
{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}
@endif
@else
{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}
@endcan

@uberbrady do you have any additional thoughts here? (I know we've been workshopping this together offline just now.)

My thoughts here:

  • Remove the superuser and admin checks
  • Add a new permission for editing/viewing encrypted custom fields

I consider this a security bug actually, so I'd consider it higher priority than anything else on deck. If you think you can't tackle this today, let me know and I'll pick it up.

@inietov
Copy link
Collaborator Author

inietov commented Jul 20, 2023

I think it now works as expected, let me know if something with the defined gate is not correct because I had a lot of fight and don't know if I created it correctly. Thanks for your patience!

Copy link
Collaborator

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

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

Assuming this is the direction we want to go in: this looks good and works 😄

@inietov
Copy link
Collaborator Author

inietov commented Jul 28, 2023

Another kind ping @snipe

@snipe snipe merged commit 2e1c3fb into snipe:develop Jul 31, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants