Skip to content

Commit a2b96be

Browse files
Potential fix for code scanning alert no. 11: Uncontrolled data used in path expression
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent ae2b306 commit a2b96be

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

builder/source/cache.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import * as Process from 'node:process'
44
import * as Path from 'node:path'
55
import { FetchAdShieldDomains } from './references/index.js'
66

7-
const BaseCacheDir = (Process.env.INIT_CWD && Path.isAbsolute(Process.env.INIT_CWD))
8-
? Process.env.INIT_CWD
9-
: Process.cwd()
10-
const CachePath = Path.join(Path.resolve(BaseCacheDir), '.buildcache')
7+
const ProjectRoot = Path.resolve(Process.cwd())
8+
const EnvInitCwd = Process.env.INIT_CWD && Path.isAbsolute(Process.env.INIT_CWD)
9+
? Path.resolve(Process.env.INIT_CWD)
10+
: null
11+
const BaseCacheDir = (EnvInitCwd && (EnvInitCwd === ProjectRoot || EnvInitCwd.startsWith(ProjectRoot + Path.sep)))
12+
? EnvInitCwd
13+
: ProjectRoot
14+
const CachePath = Path.join(BaseCacheDir, '.buildcache')
1115
const CacheDomainsPath = Path.join(CachePath, 'domains.json')
1216

1317
export function CreateCache(Domains: Set<string>) {

0 commit comments

Comments
 (0)