MCPcopy
hub / github.com/parse-community/parse-server / readFile

Method readFile

src/Routers/PagesRouter.js:495–508  ·  view source on GitHub ↗

* Reads and returns the content of a file at a given path. File reading to * serve content on the static route is only allowed from the pages * directory on downwards. * ----------------------------------------------------------------------- * **WARNING:** All file reads in the PagesRout

(filePath)

Source from the content-addressed store, hash-verified

493 * @returns {Promise<String>} The file content.
494 */
495 async readFile(filePath) {
496 // Normalize path to prevent it from containing any directory changing
497 // UNIX patterns which could expose the whole file system, e.g.
498 // `http://example.com/parse/apps/../file.txt` requests a file outside
499 // of the pages directory scope.
500 const normalizedPath = path.normalize(filePath);
501
502 // Abort if the path is outside of the path directory scope
503 if (!normalizedPath.startsWith(this.pagesPath + path.sep)) {
504 throw errors.fileOutsideAllowedScope;
505 }
506
507 return await fs.readFile(normalizedPath, 'utf-8');
508 }
509
510 /**
511 * Loads a language resource JSON file that is used for translations.

Callers 6

pageResponseMethod · 0.95
fileResponseMethod · 0.95
getTestsMethod · 0.80
getNodeVersionMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected