@@ -50,14 +50,39 @@ import {
5050 getInstallation ,
5151} from '../../services/epm/packages' ;
5252import type { BulkInstallResponse } from '../../services/epm/packages' ;
53- import { defaultIngestErrorHandler , ingestErrorToResponseOptions } from '../../errors' ;
53+ import {
54+ defaultIngestErrorHandler ,
55+ ingestErrorToResponseOptions ,
56+ IngestManagerError ,
57+ } from '../../errors' ;
5458import { splitPkgKey } from '../../services/epm/registry' ;
5559import { licenseService } from '../../services' ;
5660import { getArchiveEntry } from '../../services/epm/archive/cache' ;
5761import { getAsset } from '../../services/epm/archive/storage' ;
5862import { getPackageUsageStats } from '../../services/epm/packages/get' ;
5963import { updatePackage } from '../../services/epm/packages/update' ;
6064
65+ const ALLOWED_MIME_TYPES = [
66+ 'image/svg+xml' ,
67+ 'image/jpeg' ,
68+ 'image/png' ,
69+ 'image/gif' ,
70+ 'application/json' ,
71+ 'application/yaml' ,
72+ 'text/plain' ,
73+ 'text/markdown' ,
74+ 'text/yaml' ,
75+ ] ;
76+
77+ function validateContentTypeIsAllowed ( contentType : string ) {
78+ if ( ! ALLOWED_MIME_TYPES . includes ( contentType . split ( ';' ) [ 0 ] ) ) {
79+ throw new IngestManagerError (
80+ `File content type "${ contentType } " is not allowed to be retrieved` ,
81+ 400
82+ ) ;
83+ }
84+ }
85+
6186export const getCategoriesHandler : FleetRequestHandler <
6287 undefined ,
6388 TypeOf < typeof GetCategoriesRequestSchema . query >
@@ -152,6 +177,7 @@ export const getFileHandler: FleetRequestHandler<
152177 statusCode : 400 ,
153178 } ) ;
154179 }
180+ validateContentTypeIsAllowed ( contentType ) ;
155181
156182 return response . custom ( {
157183 body : buffer ,
@@ -172,6 +198,11 @@ export const getFileHandler: FleetRequestHandler<
172198 return headers ;
173199 } , { } as ResponseHeaders ) ;
174200
201+ if ( ! proxiedHeaders [ 'content-type' ] || typeof proxiedHeaders [ 'content-type' ] !== 'string' ) {
202+ throw new IngestManagerError ( `unknown content type for file: ${ filePath } ` ) ;
203+ }
204+ validateContentTypeIsAllowed ( proxiedHeaders [ 'content-type' ] ) ;
205+
175206 return response . custom ( {
176207 body : registryResponse . body ,
177208 statusCode : registryResponse . status ,
0 commit comments