@djangocfg/nextjs 2.1.470 → 2.1.472

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports, module) {
15
15
  module.exports = {
16
16
  name: "@djangocfg/nextjs",
17
- version: "2.1.470",
17
+ version: "2.1.472",
18
18
  description: "Next.js server utilities: sitemap, health, OG images, contact forms, navigation, config",
19
19
  keywords: [
20
20
  "nextjs",
@@ -154,6 +154,7 @@ var require_package = __commonJS({
154
154
  clean: "rm -rf dist",
155
155
  lint: "eslint .",
156
156
  check: "tsc --noEmit",
157
+ test: "tsx --test src/**/*.test.ts",
157
158
  "ai-docs": "tsx src/ai/cli.ts"
158
159
  },
159
160
  peerDependencies: {
@@ -1669,38 +1670,57 @@ function createBaseNextConfig(options = {}) {
1669
1670
  ];
1670
1671
  const hasIframeAllowlist = !!options.allowIframeFrom && options.allowIframeFrom.length > 0;
1671
1672
  const frameAncestors = hasIframeAllowlist ? options.allowIframeFrom.includes("*") ? "*" : `'self' ${options.allowIframeFrom.join(" ")}` : "'none'";
1673
+ const cspDisabled = options.csp === false;
1674
+ const cspExtra = typeof options.csp === "object" ? options.csp : void 0;
1672
1675
  const stripeScript = options.stripe ? " https://js.stripe.com" : "";
1673
1676
  const stripeConnect = options.stripe ? " https://api.stripe.com" : "";
1674
1677
  const stripeFrame = options.stripe ? " https://js.stripe.com https://checkout.stripe.com" : "";
1675
- const connectSrc = isDev ? `connect-src 'self' http: https: ws: wss:${stripeConnect}` : `connect-src 'self' https: wss:${stripeConnect}`;
1676
- const imgSrc = isDev ? "img-src 'self' data: blob: http: https:" : "img-src 'self' data: blob: https:";
1677
- const cspDirectives = [
1678
- "default-src 'self'",
1679
- // Next.js requires inline + eval for its runtime/HMR. Tighten to nonces later.
1680
- `script-src 'self' 'unsafe-inline' 'unsafe-eval'${stripeScript}`,
1681
- "style-src 'self' 'unsafe-inline'",
1682
- imgSrc,
1683
- "font-src 'self' data:",
1684
- // API/websocket calls go cross-origin to Django/Centrifugo.
1685
- connectSrc,
1686
- // Stripe Elements/Checkout mount iframes; add their hosts when enabled.
1687
- `frame-src 'self'${stripeFrame}`,
1688
- "object-src 'none'",
1689
- "base-uri 'self'",
1690
- "form-action 'self'",
1691
- `frame-ancestors ${frameAncestors}`
1692
- ];
1693
- headers.push({
1694
- source: "/:path*",
1695
- headers: [
1696
- { key: "X-Content-Type-Options", value: "nosniff" },
1697
- { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
1698
- { key: "Content-Security-Policy", value: cspDirectives.join("; ") },
1699
- // X-Frame-Options for older browsers. Omitted when a wildcard iframe
1700
- // allowlist is set (browsers then rely on CSP frame-ancestors).
1701
- ...hasIframeAllowlist && options.allowIframeFrom.includes("*") ? [] : [{ key: "X-Frame-Options", value: hasIframeAllowlist ? "SAMEORIGIN" : "DENY" }]
1702
- ]
1703
- });
1678
+ const extraScript = cspExtra?.scriptSrc?.length ? " " + cspExtra.scriptSrc.join(" ") : "";
1679
+ const extraConnect = cspExtra?.connectSrc?.length ? " " + cspExtra.connectSrc.join(" ") : "";
1680
+ const extraFrame = cspExtra?.frameSrc?.length ? " " + cspExtra.frameSrc.join(" ") : "";
1681
+ const extraImg = cspExtra?.imgSrc?.length ? " " + cspExtra.imgSrc.join(" ") : "";
1682
+ const extraFont = cspExtra?.fontSrc?.length ? " " + cspExtra.fontSrc.join(" ") : "";
1683
+ const connectSrc = isDev ? `connect-src 'self' http: https: ws: wss:${stripeConnect}${extraConnect}` : `connect-src 'self' https: wss:${stripeConnect}${extraConnect}`;
1684
+ const imgSrc = isDev ? `img-src 'self' data: blob: http: https:${extraImg}` : `img-src 'self' data: blob: https:${extraImg}`;
1685
+ if (!cspDisabled) {
1686
+ const cspDirectives = [
1687
+ "default-src 'self'",
1688
+ // Next.js requires inline + eval for its runtime/HMR. Tighten to nonces later.
1689
+ `script-src 'self' 'unsafe-inline' 'unsafe-eval'${stripeScript}${extraScript}`,
1690
+ "style-src 'self' 'unsafe-inline'",
1691
+ imgSrc,
1692
+ `font-src 'self' data:${extraFont}`,
1693
+ // API/websocket calls go cross-origin to Django/Centrifugo.
1694
+ connectSrc,
1695
+ // Stripe Elements/Checkout and any app-declared trusted origins
1696
+ // (options.csp.frameSrc) mount iframes; add their hosts when enabled.
1697
+ `frame-src 'self'${stripeFrame}${extraFrame}`,
1698
+ "object-src 'none'",
1699
+ "base-uri 'self'",
1700
+ "form-action 'self'",
1701
+ `frame-ancestors ${frameAncestors}`
1702
+ ];
1703
+ headers.push({
1704
+ source: "/:path*",
1705
+ headers: [
1706
+ { key: "X-Content-Type-Options", value: "nosniff" },
1707
+ { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
1708
+ { key: "Content-Security-Policy", value: cspDirectives.join("; ") },
1709
+ // X-Frame-Options for older browsers. Omitted when a wildcard iframe
1710
+ // allowlist is set (browsers then rely on CSP frame-ancestors).
1711
+ ...hasIframeAllowlist && options.allowIframeFrom.includes("*") ? [] : [{ key: "X-Frame-Options", value: hasIframeAllowlist ? "SAMEORIGIN" : "DENY" }]
1712
+ ]
1713
+ });
1714
+ } else {
1715
+ headers.push({
1716
+ source: "/:path*",
1717
+ headers: [
1718
+ { key: "X-Content-Type-Options", value: "nosniff" },
1719
+ { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
1720
+ ...hasIframeAllowlist && options.allowIframeFrom.includes("*") ? [] : [{ key: "X-Frame-Options", value: hasIframeAllowlist ? "SAMEORIGIN" : "DENY" }]
1721
+ ]
1722
+ });
1723
+ }
1704
1724
  const userHeaders = options.headers ? await options.headers() : [];
1705
1725
  return [...headers, ...userHeaders];
1706
1726
  },