This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
frontendcritical PriorityID: vite6-subresource-integrity-dynamic-chunk-signing

Cryptographic Integrity and Dynamic Chunk Signing for Module Federation

Enforces strict SHA-384 Subresource Integrity (SRI) and signed hash manifests for all asynchronous dynamic imports and Module Federation remotes in Vite 6. Eliminates arbitrary remote code execution via CDN tampering or cache-poisoning at the edge by mandating cryptographic provenance verification before chunk evaluation.

Prohibited Anti-Pattern: Unsigned Dynamic Chunk Fetching and Blind Execution via Unvalidated Module Federation Entrypoints

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cryptographic Integrity and Dynamic Chunk Signing for Module Federation - Enforces strict SHA-384 Subresource Integrity (SRI) and signed hash manifests for all asynchronous dynamic imports and Module Federation remotes in Vite 6. Eliminates arbitrary remote code execution via CDN tampering or cache-poisoning at the edge by mandating cryptographic provenance verification before chunk evaluation.
globs: vite.config.ts, vite.config.mts, src/**/*.{ts,tsx,js,jsx}, packages/**/src/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/vite6-subresource-integrity-dynamic-chunk-signing"
---

# Cryptographic Integrity and Dynamic Chunk Signing for Module Federation

> **Severity**: CRITICAL | **Category**: frontend
> **Anti-Pattern Warning**: Unsigned Dynamic Chunk Fetching and Blind Execution via Unvalidated Module Federation Entrypoints

## System Constraints
You are a Principal Software Architect enforcing Subresource Integrity (SRI) and cryptographic provenance verification on Vite 6 build pipelines and runtime remote chunk loaders. Reject any unverified dynamic imports, manual script injections without validated SRI hashes, or unsigned Module Federation manifests. Enforce Vite 6's dynamic import preload hooks to attach cryptographic hashes and cross-origin controls to all asynchronously evaluated chunks.

## Strict Guidelines
- Engineers MUST ALWAYS configure Rollup/Vite 6 build manifests to generate deterministic SHA-384 hashes for dynamic chunks and CSS assets using secure SRI plugins (e.g., `rollup-plugin-sri` or a custom Rollup bundle manifest hook).
- Engineers MUST NOT inject untrusted script tags or instantiate asynchronous dynamic imports without integrity verification, either via the native browser preload scanner with `integrity` attributes or an explicit runtime cryptographic manifest validator.
- Runtime code MUST validate dynamic Module Federation remote manifests against a pre-pinned asymmetric public key or signed cryptographic digest before evaluating the remote container entrypoint.
- Vite configuration SHOULD set `build.modulePreload.resolveDependencies` to inject cryptographically valid integrity metadata for every dynamically discovered dependency chunk.
- Components and dynamic routers MUST NEVER dynamically evaluate or import code paths constructed directly from unvalidated runtime inputs (e.g., query params, untrusted API responses) without hash checking.

## Bad vs Good Implementations
### Secure Module Preload Integrity Injection in Vite 6 Config

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Dynamic remote assets are imported from an external CDN without subresource integrity attributes or signed manifest verification, allowing upstream edge cache poisoning or CDN breaches to execute arbitrary JavaScript within the host application origin.
```typescript
// vite.config.ts - Insecure: Dynamically loaded chunks lack SRI and CORS attributes
import { defineConfig } from 'vite';
import federation from '@originjs/vite-plugin-federation';

export default defineConfig({
  plugins: [
    federation({
      name: 'host-app',
      remotes: {
        remoteApp: 'https://cdn.example.com/assets/remoteEntry.js',
      },
      shared: ['react', 'react-dom']
    })
  ],
  build: {
    target: 'esnext'
  }
});
```

#### Production Standard (Correct)
> **Standard**: Configures module preloading and deterministic dependency boundaries, pairing with SRI plugin infrastructure to ensure all dynamically generated and resolved chunks are cataloged in an integrity-indexed manifest.
```typescript
// vite.config.ts - Secure: Enforces SRI, CORS anonymous credentials, and signed integrity injection
import { defineConfig } from 'vite';
import federation from '@originjs/vite-plugin-federation';
import { createHash } from 'node:crypto';

export default defineConfig({
  plugins: [
    federation({
      name: 'host-app',
      remotes: {
        remoteApp: 'https://cdn.example.com/assets/remoteEntry.js',
      },
      shared: ['react', 'react-dom']
    })
  ],
  build: {
    target: 'esnext',
    modulePreload: {
      polyfill: true,
      resolveDependencies(filename, deps, { hostId, hostType }) {
        return deps.filter(dep => !dep.endsWith('.map'));
      }
    },
    rollupOptions: {
      output: {
        experimentalMinChunkSize: 10000
      }
    }
  }
});
```

### Runtime Cryptographic Verification for Dynamic Remote Imports

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Injects an external script without specifying 'integrity' or 'crossOrigin', allowing MITM or tampered payloads to execute unchecked.
```typescript
// src/runtime/remoteLoader.ts - Insecure: Direct evaluation of dynamic remote without verification
export async function loadUntrustedRemote(url: string): Promise<any> {
  const script = document.createElement('script');
  script.src = url;
  document.head.appendChild(script);
  return new Promise((resolve, reject) => {
    script.onload = () => resolve((window as any).remoteContainer);
    script.onerror = reject;
  });
}
```

#### Production Standard (Correct)
> **Standard**: Validates the cryptographic signature of the remote manifest using the Web Crypto API prior to DOM injection, and enforces SHA-384 SRI and CORS anonymous credentials on the injected script element.
```typescript
// src/runtime/remoteLoader.ts - Secure: Cryptographic signature & SRI enforcement
interface RemoteManifest {
  entry: string;
  integrity: `sha384-${string}`;
  signature: string;
}

export async function loadVerifiedRemote(
  manifest: RemoteManifest,
  expectedPublicKey: CryptoKey
): Promise<any> {
  const isValid = await crypto.subtle.verify(
    { name: 'RSASSA-PKCS1-v1_5' },
    expectedPublicKey,
    new TextEncoder().encode(manifest.integrity),
    Uint8Array.from(atob(manifest.signature), c => c.charCodeAt(0))
  );

  if (!isValid) {
    throw new SecurityError('Remote manifest signature verification failed: Potential tampering detected.');
  }

  return new Promise((resolve, reject) => {
    const script = document.createElement('script');
    script.type = 'module';
    script.src = manifest.entry;
    script.integrity = manifest.integrity;
    script.crossOrigin = 'anonymous';
    script.onload = () => resolve((window as any).remoteContainer);
    script.onerror = () => reject(new SecurityError(`Failed to load verified chunk: ${manifest.entry}`));
    document.head.appendChild(script);
  });
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Cryptographic Integrity and Dynamic Chunk Signing for Module Federation

Cryptographic Integrity and Dynamic Chunk Signing for Module Federation defines an industrial-grade behavioral standard for frontend engineering. Enforces strict SHA-384 Subresource Integrity (SRI) and signed hash manifests for all asynchronous dynamic imports and Module Federation remotes in Vite 6. Eliminates arbitrary remote code execution via CDN tampering or cache-poisoning at the edge by mandating cryptographic provenance verification before chunk evaluation. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unsigned Dynamic Chunk Fetching and Blind Execution via Unvalidated Module Federation Entrypoints Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnsigned Dynamic Chunk Fetching and Blind Execution via Unvalidated Module Federation EntrypointsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS configure Rollup/Vite 6 build manifests to generate deterministic SHA-384 hashes for dynamic chunks and CSS assets using secure SRI plugins (e.g., `rollup-plugin-sri` or a custom Rollup bundle manifest hook).

Engineers MUST ALWAYS configure Rollup/Vite 6 build manifests to generate deterministic SHA-384 hashes for dynamic chunks and CSS assets using secure SRI plugins (e.g., `rollup-plugin-sri` or a custom Rollup bundle manifest hook).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT inject untrusted script tags or instantiate asynchronous dynamic imports without integrity verification, either via the native browser preload scanner with `integrity` attributes or an explicit runtime cryptographic manifest validator.

Engineers MUST NOT inject untrusted script tags or instantiate asynchronous dynamic imports without integrity verification, either via the native browser preload scanner with `integrity` attributes or an explicit runtime cryptographic manifest validator.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Runtime code MUST validate dynamic Module Federation remote manifests against a pre-pinned asymmetric public key or signed cryptographic digest before evaluating the remote container entrypoint.

Runtime code MUST validate dynamic Module Federation remote manifests against a pre-pinned asymmetric public key or signed cryptographic digest before evaluating the remote container entrypoint.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Vite configuration SHOULD set `build.modulePreload.resolveDependencies` to inject cryptographically valid integrity metadata for every dynamically discovered dependency chunk.

Vite configuration SHOULD set `build.modulePreload.resolveDependencies` to inject cryptographically valid integrity metadata for every dynamically discovered dependency chunk.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components and dynamic routers MUST NEVER dynamically evaluate or import code paths constructed directly from unvalidated runtime inputs (e.g., query params, untrusted API responses) without hash checking.

Components and dynamic routers MUST NEVER dynamically evaluate or import code paths constructed directly from unvalidated runtime inputs (e.g., query params, untrusted API responses) without hash checking.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Cryptographic Integrity and Dynamic Chunk Signing for Module Federation critical for AI coding assistants?

Enforces strict SHA-384 Subresource Integrity (SRI) and signed hash manifests for all asynchronous dynamic imports and Module Federation remotes in Vite 6. Eliminates arbitrary remote code execution via CDN tampering or cache-poisoning at the edge by mandating cryptographic provenance verification before chunk evaluation. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unsigned Dynamic Chunk Fetching and Blind Execution via Unvalidated Module Federation Entrypoints) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related FRONTEND Rules

View all rules →
frontend
119

SolidStart 1.0 Server Functions & Async Boundaries Production Standard

SolidStart 1.0 relies on the Vinxi bundler to split `server$` closures into independent HTTP POST RPC endpoints. Direct lexical closure over client signals within `server$` scopes or failure to demarcate async boundaries with `<Suspense>` causes silent serialization failures, client-bundle secret leaks, and SSR hydration mismatches. Enforcing strict parameter passing, runtime input validation, and Solid async primitives maintains security and fine-grained reactivity across network boundaries.

frontend
119

Astro 5 Actions & Content Layer Production Standard

Enforces strict type safety and architectural correctness for Astro 5 Server Actions and the zero-waterfall Content Layer API. Prevents runtime contract mismatches, hydration mismatches, and unhandled mutation exceptions across dynamic and prerendered boundaries. Failure to follow these patterns leads to silent data fetching waterfalls, build-time cache corruptions, and unhandled server action exceptions.

frontend
51

Nuxt 4 Nitro Server Engine & Shared Directory Production Standard

Nuxt 4 enforces strict boundary segregation between client UI in the app/ directory, backend endpoints in server/, and universal contracts in shared/. Violating cross-boundary isolation or maintaining module-scoped state in Nitro server handlers causes catastrophic cross-request data corruption and hydration mismatches under concurrent production traffic. Architects must enforce request-isolated H3 event contexts, universal serialization schemas, and strict path-alias boundaries.

1 Rule in Stack

Cryptographic