Skip to content

Commit d874386

Browse files
committed
Don't allow opening of files we know cannot be edited; closes pterodactyl#2286
1 parent 906cfce commit d874386

File tree

6 files changed

+65
-65
lines changed

6 files changed

+65
-65
lines changed

app/Transformers/Daemon/FileObjectTransformer.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ class FileObjectTransformer extends BaseDaemonTransformer
1414
*/
1515
private $editable = [];
1616

17-
/**
18-
* FileObjectTransformer constructor.
19-
*/
20-
public function __construct()
21-
{
22-
$this->editable = config('pterodactyl.files.editable', []);
23-
}
24-
2517
/**
2618
* Transform a file object response from the daemon into a standardized response.
2719
*
@@ -36,8 +28,7 @@ public function transform(array $item)
3628
'size' => Arr::get($item, 'size'),
3729
'is_file' => Arr::get($item, 'file', true),
3830
'is_symlink' => Arr::get($item, 'symlink', false),
39-
'is_editable' => in_array(Arr::get($item, 'mime', ''), $this->editable),
40-
'mimetype' => Arr::get($item, 'mime'),
31+
'mimetype' => Arr::get($item, 'mime', 'application/octet-stream'),
4132
'created_at' => Carbon::parse(Arr::get($item, 'created', ''))->toIso8601String(),
4233
'modified_at' => Carbon::parse(Arr::get($item, 'modified', ''))->toIso8601String(),
4334
];

config/pterodactyl.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,6 @@
178178
*/
179179
'files' => [
180180
'max_edit_size' => env('PTERODACTYL_FILES_MAX_EDIT_SIZE', 1024 * 1024 * 4),
181-
'editable' => [
182-
'application/json',
183-
'application/javascript',
184-
'application/xml',
185-
'application/xhtml+xml',
186-
'inode/x-empty',
187-
'text/xml',
188-
'text/css',
189-
'text/html',
190-
'text/plain',
191-
'text/x-perl',
192-
'text/x-shellscript',
193-
'text/x-python',
194-
],
195181
],
196182

197183
/*

resources/scripts/api/server/files/loadDirectory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export interface FileObject {
88
size: number;
99
isFile: boolean;
1010
isSymlink: boolean;
11-
isEditable: boolean;
1211
mimetype: string;
1312
createdAt: Date;
1413
modifiedAt: Date;
1514
isArchiveType: () => boolean;
15+
isEditable: () => boolean;
1616
}
1717

1818
export default async (uuid: string, directory?: string): Promise<FileObject[]> => {

resources/scripts/api/transformers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
1919
size: Number(data.attributes.size),
2020
isFile: data.attributes.is_file,
2121
isSymlink: data.attributes.is_symlink,
22-
isEditable: data.attributes.is_editable,
2322
mimetype: data.attributes.mimetype,
2423
createdAt: new Date(data.attributes.created_at),
2524
modifiedAt: new Date(data.attributes.modified_at),
@@ -39,6 +38,19 @@ export const rawDataToFileObject = (data: FractalResponseData): FileObject => ({
3938
'application/zip', // .zip
4039
].indexOf(this.mimetype) >= 0;
4140
},
41+
42+
isEditable: function () {
43+
if (this.isArchiveType() || !this.isFile) return false;
44+
45+
const matches = [
46+
'application/jar',
47+
'application/octet-stream',
48+
'inode/directory',
49+
/^image\//,
50+
];
51+
52+
return matches.every(m => !this.mimetype.match(m));
53+
},
4254
});
4355

4456
export const rawDataToServerBackup = ({ attributes }: FractalResponseData): ServerBackup => ({

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

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Row = styled.div`
1616
${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`};
1717
`;
1818

19-
const FileObjectRow = ({ file }: { file: FileObject }) => {
19+
const Clickable: React.FC<{ file: FileObject }> = memo(({ file, children }) => {
2020
const directory = ServerContext.useStoreState(state => state.files.directory);
2121

2222
const history = useHistory();
@@ -35,48 +35,59 @@ const FileObjectRow = ({ file }: { file: FileObject }) => {
3535
};
3636

3737
return (
38-
<Row
39-
key={file.name}
40-
onContextMenu={e => {
41-
e.preventDefault();
42-
window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX }));
43-
}}
44-
>
45-
<SelectFileCheckbox name={file.name}/>
38+
file.isFile && !file.isEditable() ?
39+
<div css={tw`flex flex-1 text-neutral-300 no-underline p-3 cursor-default`}>
40+
{children}
41+
</div>
42+
:
4643
<NavLink
4744
to={`${match.url}/${file.isFile ? 'edit/' : ''}#${cleanDirectoryPath(`${directory}/${file.name}`)}`}
4845
css={tw`flex flex-1 text-neutral-300 no-underline p-3`}
4946
onClick={onRowClick}
5047
>
51-
<div css={tw`flex-none self-center text-neutral-400 mr-4 text-lg pl-3 ml-6`}>
52-
{file.isFile ?
53-
<FontAwesomeIcon icon={file.isSymlink ? faFileImport : file.isArchiveType() ? faFileArchive : faFileAlt}/>
54-
:
55-
<FontAwesomeIcon icon={faFolder}/>
56-
}
57-
</div>
58-
<div css={tw`flex-1`}>
59-
{file.name}
60-
</div>
61-
{file.isFile &&
62-
<div css={tw`w-1/6 text-right mr-4`}>
63-
{bytesToHuman(file.size)}
64-
</div>
65-
}
66-
<div
67-
css={tw`w-1/5 text-right mr-4`}
68-
title={file.modifiedAt.toString()}
69-
>
70-
{Math.abs(differenceInHours(file.modifiedAt, new Date())) > 48 ?
71-
format(file.modifiedAt, 'MMM do, yyyy h:mma')
72-
:
73-
formatDistanceToNow(file.modifiedAt, { addSuffix: true })
74-
}
75-
</div>
48+
{children}
7649
</NavLink>
77-
<FileDropdownMenu file={file}/>
78-
</Row>
7950
);
80-
};
51+
}, isEqual);
52+
53+
const FileObjectRow = ({ file }: { file: FileObject }) => (
54+
<Row
55+
key={file.name}
56+
onContextMenu={e => {
57+
e.preventDefault();
58+
window.dispatchEvent(new CustomEvent(`pterodactyl:files:ctx:${file.key}`, { detail: e.clientX }));
59+
}}
60+
>
61+
<SelectFileCheckbox name={file.name}/>
62+
<Clickable file={file}>
63+
<div css={tw`flex-none self-center text-neutral-400 mr-4 text-lg pl-3 ml-6`}>
64+
{file.isFile ?
65+
<FontAwesomeIcon icon={file.isSymlink ? faFileImport : file.isArchiveType() ? faFileArchive : faFileAlt}/>
66+
:
67+
<FontAwesomeIcon icon={faFolder}/>
68+
}
69+
</div>
70+
<div css={tw`flex-1`}>
71+
{file.name}
72+
</div>
73+
{file.isFile &&
74+
<div css={tw`w-1/6 text-right mr-4`}>
75+
{bytesToHuman(file.size)}
76+
</div>
77+
}
78+
<div
79+
css={tw`w-1/5 text-right mr-4`}
80+
title={file.modifiedAt.toString()}
81+
>
82+
{Math.abs(differenceInHours(file.modifiedAt, new Date())) > 48 ?
83+
format(file.modifiedAt, 'MMM do, yyyy h:mma')
84+
:
85+
formatDistanceToNow(file.modifiedAt, { addSuffix: true })
86+
}
87+
</div>
88+
</Clickable>
89+
<FileDropdownMenu file={file}/>
90+
</Row>
91+
);
8192

82-
export default memo(FileObjectRow, (prevProps, nextProps) => isEqual(prevProps.file, nextProps.file));
93+
export default memo(FileObjectRow, isEqual);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ const generateDirectoryData = (name: string): FileObject => ({
2626
mode: '0644',
2727
size: 0,
2828
isFile: false,
29-
isEditable: false,
3029
isSymlink: false,
3130
mimetype: '',
3231
createdAt: new Date(),
3332
modifiedAt: new Date(),
3433
isArchiveType: () => false,
34+
isEditable: () => false,
3535
});
3636

3737
export default () => {

0 commit comments

Comments
 (0)