You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/configuration/nativescript.md
+145Lines changed: 145 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,6 +171,60 @@ hooks: Array = []
171
171
172
172
See [Hooks Configuration Reference](#hooks-configuration-reference)
173
173
174
+
### security
175
+
176
+
NativeScript supports dynamic `import()` from remote URLs. This is useful during development but carries security implications in production since NativeScript code has **direct access to native platform APIs** (file system, keychain, network, camera, etc.).
177
+
178
+
| Mode | Remote Modules |
179
+
|------|----------------|
180
+
|**Debug**| ✅ Always allowed |
181
+
|**Production**| ❌ Blocked by default |
182
+
183
+
#### Enabling Remote Modules in Production
184
+
185
+
If you need remote ES modules in production, explicitly opt-in:
The allowlist uses **prefix matching** — a URL is allowed if it starts with any entry.
218
+
219
+
#### Security Best Practices
220
+
221
+
-**Keep production secure by default** - Don't enable unless necessary
222
+
-**Use narrow allowlists** - Specific paths, not broad domains
223
+
-**Pin versions in URLs** - Use immutable, versioned URLs
224
+
-**Never use user-controlled URLs** - Injection vulnerability risk
225
+
226
+
For comprehensive security guidance, see the [Security Guide](/guide/security).
227
+
174
228
## CLI Configuration Reference
175
229
176
230
### cli.packageManager
@@ -482,3 +536,94 @@ Available hooks (prefix with `before-` or `after-`):
482
536
-`watchPatterns` - Set up watch patterns, runs during `watch` hook
483
537
484
538
<!-- TODO: check if we are missing some hooks here, ie. before-gradleArgs? -->
539
+
540
+
## Security Configuration Reference
541
+
542
+
NativeScript provides security configuration options to control sensitive runtime behaviors, particularly around remote code execution via ES module imports.
543
+
544
+
::: tip
545
+
For comprehensive security guidance and best practices, see the [Security Guide](/guide/security).
546
+
:::
547
+
548
+
### security.allowRemoteModules
549
+
550
+
```ts
551
+
security.allowRemoteModules: boolean=false;
552
+
```
553
+
554
+
Enable remote ES module loading in production builds.
|**Production** (Release builds) | ❌ Blocked by default |
560
+
561
+
When `false` (the default), any attempt to `import("https://...")` in production will throw an error. This is a security measure because NativeScript code has **direct access to native platform APIs** (file system, keychain, network, camera, etc.).
562
+
563
+
```ts
564
+
exportdefault {
565
+
// ...
566
+
security: {
567
+
allowRemoteModules: true
568
+
}
569
+
} asNativeScriptConfig
570
+
```
571
+
572
+
::: warning Security Implications
573
+
Remote modules bypass App Store/Play Store code review and can access any native API your app has access to. Only enable this if you have a specific, justified need and understand the implications.
574
+
:::
575
+
576
+
### security.remoteModuleAllowlist
577
+
578
+
```ts
579
+
security.remoteModuleAllowlist: string[] = [];
580
+
```
581
+
582
+
Restrict remote modules to specific URL prefixes. Only used when `allowRemoteModules` is `true`.
583
+
584
+
The allowlist uses **prefix matching** — a URL is allowed if it starts with any entry in the list.
If the allowlist is empty or not provided (and `allowRemoteModules` is `true`), all HTTPS URLs are allowed — this is **not recommended** for production.
608
+
609
+
### Error Messages
610
+
611
+
When remote module loading is blocked, you'll see clear error messages:
612
+
613
+
```
614
+
// Remote modules disabled
615
+
Remote ES modules are not allowed in production. URL: https://example.com/mod.js.
616
+
Enable via security.allowRemoteModules in nativescript.config.ts
617
+
618
+
// URL not in allowlist
619
+
Remote URL not in security.remoteModuleAllowlist: https://untrusted.com/mod.js
620
+
```
621
+
622
+
### Best Practices
623
+
624
+
1.**Keep production secure by default** — Don't enable `allowRemoteModules` unless necessary
625
+
2.**Use narrow allowlists** — Specific paths, not broad domains
626
+
3.**Pin versions in URLs** — Use immutable, versioned URLs over mutable endpoints
627
+
4.**Never use user-controlled URLs** — Avoid injection vulnerabilities
628
+
629
+
For more details on security implications and additional best practices, see the [Security Guide](/guide/security).
0 commit comments