mirror of
https://github.com/github/codeql.git
synced 2026-01-08 20:20:34 +01:00
JS: Ensure we never write outside the scratch dir
This commit is contained in:
@@ -689,6 +689,19 @@ public class AutoBuild {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a relative path from <code>from</code> to <code>to</code> provided
|
||||
* the latter is contained in the former. Otherwise returns <code>null</code>.
|
||||
* @return a path or null
|
||||
*/
|
||||
public static Path tryRelativize(Path from, Path to) {
|
||||
Path relative = from.relativize(to);
|
||||
if (relative.startsWith("..") || relative.isAbsolute()) {
|
||||
return null;
|
||||
}
|
||||
return relative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs dependencies for use by the TypeScript type checker.
|
||||
* <p>
|
||||
@@ -727,6 +740,9 @@ public class AutoBuild {
|
||||
if (!(json instanceof JsonObject)) continue;
|
||||
JsonObject jsonObject = (JsonObject) json;
|
||||
file = file.toAbsolutePath();
|
||||
if (tryRelativize(sourceRoot, file) == null) {
|
||||
continue; // Ignore package.json files outside the source root.
|
||||
}
|
||||
packageJsonFiles.put(file, jsonObject);
|
||||
|
||||
String name = getChildAsString(jsonObject, "name");
|
||||
|
||||
Reference in New Issue
Block a user