Skip to content

Commit 8e0f8cc

Browse files
authored
fix: use node resolver to prevent escaped traversal errors (#506)
1 parent 00df11b commit 8e0f8cc

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

packages/uniwind/src/core/config/config.common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class UniwindConfigBuilder {
101101
// noop
102102
}
103103

104-
// oxlint-disable-next-line typescript/no-redundant-type-constituents
104+
// oxlint-disable-next-line typescript/no-unused-vars
105105
updateInsets(insets: Insets) {
106106
// noop
107107
}

packages/uniwind/src/metro/resolvers.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CustomResolutionContext, CustomResolver } from 'metro-resolver'
2-
import { basename, dirname, join, sep } from 'node:path'
2+
import { basename, dirname, sep } from 'node:path'
33

44
type ResolverConfig = {
55
platform: string | null
@@ -45,12 +45,11 @@ export const nativeResolver = ({
4545
const resolution = resolver(context, moduleName, platform)
4646

4747
if (cachedInternalBasePath === null) {
48-
const componentsResolution = resolver(context, 'uniwind/components', platform)
49-
50-
cachedInternalBasePath = componentsResolution.type === 'sourceFile'
51-
// Go from src/components to root
52-
? join(dirname(componentsResolution.filePath), '../..')
53-
: ''
48+
try {
49+
cachedInternalBasePath = dirname(require.resolve('uniwind/package.json'))
50+
} catch {
51+
cachedInternalBasePath = ''
52+
}
5453
}
5554

5655
const isInternal = cachedInternalBasePath !== '' && context.originModulePath.startsWith(cachedInternalBasePath)
@@ -94,13 +93,13 @@ export const webResolver = ({
9493
const resolution = resolver(context, moduleName, platform)
9594

9695
if (cachedInternalBasePath === null) {
97-
const componentsResolution = resolver(context, 'uniwind/components', platform)
98-
99-
cachedInternalBasePath = componentsResolution.type === 'sourceFile'
100-
// Go from dist/module/components/web to root
101-
? join(dirname(componentsResolution.filePath), '../../../..')
102-
: ''
96+
try {
97+
cachedInternalBasePath = dirname(require.resolve('uniwind/package.json'))
98+
} catch {
99+
cachedInternalBasePath = ''
100+
}
103101
}
102+
104103
if (
105104
(cachedInternalBasePath !== '' && context.originModulePath.startsWith(cachedInternalBasePath))
106105
|| resolution.type !== 'sourceFile'

0 commit comments

Comments
 (0)