-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: migrate typhoon to new-mock #1488
base: master
Are you sure you want to change the base?
Conversation
@arsforza FYI: I did some quick initial work on migrating typhoon to new mock, but I'm going to quit it now. Just so you know, whenever you get to it. |
a529a10
to
776e335
Compare
trackFileName = `${filePath}/typhoon-track-no-landfall-yet.json`; | ||
} | ||
|
||
const trackRaw = fs.readFileSync(trackFileName, 'utf-8'); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
This path depends on a
user-provided value
This path depends on a
user-provided value
This path depends on a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the problem, we need to ensure that the constructed file path is contained within a safe root directory. This can be achieved by normalizing the path using path.resolve
and then checking that the normalized path starts with the root directory. If the path is not within the root directory, we should reject the request.
- Import the
path
module. - Define a constant for the root directory.
- Normalize the constructed file path using
path.resolve
. - Check if the normalized path starts with the root directory.
- If the path is valid, proceed with reading the file; otherwise, handle the error appropriately.
-
Copy modified line R2 -
Copy modified lines R298-R300 -
Copy modified line R303 -
Copy modified lines R305-R309
@@ -1,2 +1,3 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { Injectable } from '@nestjs/common'; | ||
@@ -296,9 +297,14 @@ | ||
) { | ||
const filePath = `./src/scripts/mock-data/${DisasterType.Typhoon}/${countryCodeISO3}/${scenarioName}/${event.eventName}`; | ||
let trackFileName = `${filePath}/typhoon-track.json`; | ||
const ROOT_DIR = path.resolve('./src/scripts/mock-data'); | ||
const filePath = path.resolve(ROOT_DIR, `${DisasterType.Typhoon}/${countryCodeISO3}/${scenarioName}/${event.eventName}`); | ||
let trackFileName = path.resolve(filePath, 'typhoon-track.json'); | ||
// TODO: Implement the following scenarios | ||
if (scenarioName === TyphoonScenario.EventNoLandfall) { | ||
trackFileName = `${filePath}/typhoon-track-no-landfall.json`; | ||
trackFileName = path.resolve(filePath, 'typhoon-track-no-landfall.json'); | ||
} else if (scenarioName === TyphoonScenario.EventNoLandfallYet) { | ||
trackFileName = `${filePath}/typhoon-track-no-landfall-yet.json`; | ||
trackFileName = path.resolve(filePath, 'typhoon-track-no-landfall-yet.json'); | ||
} | ||
|
||
if (!trackFileName.startsWith(ROOT_DIR)) { | ||
throw new Error('Invalid file path'); | ||
} |
No description provided.