-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add deno-import-check built-in hook to validate and enforce policies for remote imports, helping teams secure their Deno supply chain.
Motivation
Deno's remote imports are powerful but create security risks:
- Imports from untrusted sources
- No visibility into import origins
- Supply chain attack vectors
- No policy enforcement
This is a Deno-specific problem that Node.js doesn't have, making it a perfect differentiator.
Proposed Solution
hooks:
pre-commit:
- id: import-policy
run: deno-import-check
glob: "**/*.ts"
config:
allowedHosts:
- "deno.land"
- "jsr.io"
- "esm.sh"
blockList:
- "unpkg.com" # Known security issues
requireLockfile: true
checkForSecrets: true # Detect secrets in import URLsImplementation
Built-in hook that:
- Scans staged .ts files for import statements
- Extracts remote import URLs
- Validates against allowed/blocked hosts
- Checks if deno.lock is updated
- Scans for suspicious patterns (secrets in URLs, etc.)
async function denoImportCheck(ctx: HookContext): Promise<HookResult> {
const { files, rootDir, config } = ctx;
const violations: string[] = [];
for (const file of files) {
const content = await Deno.readTextFile(`${rootDir}/${file}`);
const imports = extractRemoteImports(content);
for (const importUrl of imports) {
const host = new URL(importUrl).hostname;
// Check blocklist
if (config.blockList?.includes(host)) {
violations.push(`${file}: Blocked host ${host}`);
}
// Check allowlist (if specified)
if (config.allowedHosts && !config.allowedHosts.includes(host)) {
violations.push(`${file}: Unauthorized host ${host}`);
}
// Check for secrets
if (config.checkForSecrets && hasSecretsInUrl(importUrl)) {
violations.push(`${file}: Potential secret in import URL`);
}
}
}
if (violations.length > 0) {
return {
success: false,
message: violations.join("\n"),
};
}
return { success: true, message: "All imports validated" };
}Benefits
- ✅ Unique to Deno - Node.js doesn't have remote imports
- ✅ Security value: Prevent supply chain attacks
- ✅ Compliance: Enterprise teams need import governance
- ✅ Visibility: See exactly what external code you're depending on
- ✅ Marketing: "Secure your Deno supply chain"
Configuration Options
allowedHosts: Whitelist of allowed import hostsblockList: Blacklist of forbidden hostsrequireLockfile: Ensure deno.lock is updated with importscheckForSecrets: Detect potential secrets in import URLswarnOnly: Report violations without blocking commit
Use Cases
Open source projects:
config:
allowedHosts: ["deno.land", "jsr.io", "esm.sh"]
requireLockfile: trueEnterprise projects:
config:
allowedHosts: ["internal-registry.company.com", "jsr.io"]
blockList: ["unpkg.com", "cdn.jsdelivr.net"]
checkForSecrets: truePriority
MEDIUM - High value for enterprise/security-conscious teams, but more complex to implement
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request