* 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)
| 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. |
no outgoing calls
no test coverage detected