Skip to content

Commit 981edb0

Browse files
committed
Require specific permission for reading the actual contents of a file; ref pterodactyl#2288
1 parent d874386 commit 981edb0

File tree

4 files changed

+7
-53
lines changed

4 files changed

+7
-53
lines changed

app/Http/Controllers/Api/Remote/FileDownloadController.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

app/Http/Requests/Api/Client/Servers/Files/GetFileContentsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GetFileContentsRequest extends ClientApiRequest implements ClientPermissio
1717
*/
1818
public function permission(): string
1919
{
20-
return Permission::ACTION_FILE_READ;
20+
return Permission::ACTION_FILE_READ_CONTENT;
2121
}
2222

2323
/**

app/Models/Permission.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Permission extends Model
4949
const ACTION_ALLOCATION_DELETE = 'allocation.delete';
5050

5151
const ACTION_FILE_READ = 'file.read';
52+
const ACTION_FILE_READ_CONTENT = 'file.read-content';
5253
const ACTION_FILE_CREATE = 'file.create';
5354
const ACTION_FILE_UPDATE = 'file.update';
5455
const ACTION_FILE_DELETE = 'file.delete';
@@ -138,7 +139,8 @@ class Permission extends Model
138139
'description' => 'Permissions that control a user\'s ability to modify the filesystem for this server.',
139140
'keys' => [
140141
'create' => 'Allows a user to create additional files and folders via the Panel or direct upload.',
141-
'read' => 'Allows a user to view the contents of a directory and read the contents of a file. Users with this permission can also download files.',
142+
'read' => 'Allows a user to view the contents of a directory, but not view the contents of or download files.',
143+
'read-content' => 'Allows a user to view the contents of a given file. This will also allow the user to download files.',
142144
'update' => 'Allows a user to update the contents of an existing file or directory.',
143145
'delete' => 'Allows a user to delete files or directories.',
144146
'archive' => 'Allows a user to archive the contents of a directory as well as decompress existing archives on the system.',

resources/scripts/components/server/files/FileObjectRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import tw from 'twin.macro';
1111
import isEqual from 'react-fast-compare';
1212
import styled from 'styled-components/macro';
1313
import SelectFileCheckbox from '@/components/server/files/SelectFileCheckbox';
14+
import { usePermissions } from '@/plugins/usePermissions';
1415

1516
const Row = styled.div`
1617
${tw`flex bg-neutral-700 rounded-sm mb-px text-sm hover:text-neutral-100 cursor-pointer items-center no-underline hover:bg-neutral-600`};
1718
`;
1819

1920
const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
21+
const [ canReadContents ] = usePermissions([ 'file.read-content' ]);
2022
const directory = ServerContext.useStoreState(state => state.files.directory);
2123

2224
const history = useHistory();
@@ -35,7 +37,7 @@ const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
3537
};
3638

3739
return (
38-
file.isFile && !file.isEditable() ?
40+
(!canReadContents || (file.isFile && !file.isEditable())) ?
3941
<div css={tw`flex flex-1 text-neutral-300 no-underline p-3 cursor-default`}>
4042
{children}
4143
</div>

0 commit comments

Comments
 (0)