{"record":{"id":"8583301437d6aa09","repo":"apple/pkl","slug":"insufficientmoduletrustlevel","errorCode":"insufficientModuleTrustLevel","errorMessage":"insufficientModuleTrustLevel","messagePattern":"insufficientModuleTrustLevel","errorType":"error_code","errorClass":"SecurityManagerException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/SecurityManagers.java","lineNumber":171,"sourceCode":"    public void checkResolveResource(URI resource) throws SecurityManagerException {\n      checkRead(resource, allowedResources, true);\n    }\n\n    @Override\n    public void checkReadResource(URI uri) throws SecurityManagerException {\n      checkRead(uri, allowedResources, true);\n    }\n\n    @Override\n    public void checkImportModule(URI importingModule, URI importedModule)\n        throws SecurityManagerException {\n      var importingTrustLevel = trustLevels.apply(importingModule);\n      var importedTrustLevel = trustLevels.apply(importedModule);\n\n      if (importingTrustLevel < importedTrustLevel) {\n        var message =\n            ErrorMessages.create(\"insufficientModuleTrustLevel\", importedModule, importingModule);\n        throw new SecurityManagerException(message);\n      }\n    }\n\n    @Override\n    public @Nullable Path resolveSecurePath(URI uri, boolean isResource)\n        throws SecurityManagerException, IOException {\n      if (rootDir == null\n          || !uri.isAbsolute()\n          || !uri.getScheme().equals(\"file\")\n          || (uri.getAuthority() != null && !uri.getAuthority().isEmpty())) {\n        return null;\n      }\n      var path = Path.of(uri);\n      var realPath = path.toRealPath();\n      if (!realPath.startsWith(rootDir)) {\n        var errorMessageKey = isResource ? \"resourcePastRootDir\" : \"modulePastRootDir\";\n        var message = ErrorMessages.create(errorMessageKey, uri, rootDir);\n        throw new SecurityManagerException(message);","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/SecurityManagers.java#L153-L189","documentation":"Pkl's module security manager enforces per-module trust levels. When an importing module has a strictly lower trust level than the module it tries to import, checkImportModule throws a SecurityManagerException with error code `insufficientModuleTrustLevel`, blocking the import at evaluation time.","triggerScenarios":"A module imports (via `import ...` or module loader) another module whose computed trust level (based on its URI/origin, e.g. remote HTTPS vs local path) is higher than the importing module's trust level, under a security manager with module trust checks enabled.","commonSituations":"A local untrusted module trying to import from a trusted dependency; sandboxed/CLI evaluation where project dependencies come from more-trusted origins; changes to security policies or dependency sources that shift trust levels.","solutions":["Raise the trust level of the importing module (e.g. run within a trusted project/module context)","Lower the trust requirement of the imported dependency (vendor it locally, use a less-trusted origin consistent with policy)","Adjust the security manager policy/trust mapping so the import is allowed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// compare trust levels before importing, when possible\n// ensure importingModuleTrustLevel >= importedModuleTrustLevel","typeGuard":null,"tryCatchPattern":"try {\n  return moduleLoader.load(importedModuleUri);\n} catch (SecurityManagerException e) {\n  if (e.getMessage().contains(\"insufficientModuleTrustLevel\")) {\n    // surface a policy fix hint or load from a permitted origin\n  }\n  throw e;\n}","preventionTips":["Align dependency origins with the trust policy before adding imports","Vendor external dependencies locally when running in low-trust contexts","Review security-manager/trust configuration when upgrading dependencies"],"tags":["security","pkl","module-import","trust"],"backgroundTag":"permission-denied","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}