|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * Post update functions for Next. |
| 6 | + * |
| 7 | + * All empty post-update hooks ensure the cache is cleared. |
| 8 | + * @see https://www.drupal.org/node/2960601 |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * SECURITY: Remove automatic CORS enablement. |
| 13 | + * |
| 14 | + * The Next module previously forced CORS to be enabled with permissive default |
| 15 | + * settings (Access-Control-Allow-Origin: *), which created a security |
| 16 | + * vulnerability. |
| 17 | + * |
| 18 | + * CORS is only required if your Next.js application makes client-side browser |
| 19 | + * requests to your Drupal API (e.g., useEffect, useSWR, client components). |
| 20 | + * Most Next.js applications use server-side data fetching and do not need CORS. |
| 21 | + * |
| 22 | + * If your site requires CORS, you must now configure it explicitly in your |
| 23 | + * sites/default/services.yml file. See the module's CORS.md file or |
| 24 | + * https://www.drupal.org/node/2715637 for proper CORS configuration. |
| 25 | + * |
| 26 | + * Example CORS configuration for Next.js sites with client-side fetching: |
| 27 | + * @code |
| 28 | + * parameters: |
| 29 | + * cors.config: |
| 30 | + * enabled: true |
| 31 | + * allowedHeaders: ['x-csrf-token', 'authorization', 'content-type', 'accept'] |
| 32 | + * allowedMethods: ['GET', 'POST', 'OPTIONS'] |
| 33 | + * allowedOrigins: ['https://www.your-site.com'] |
| 34 | + * exposedHeaders: false |
| 35 | + * maxAge: false |
| 36 | + * supportsCredentials: true |
| 37 | + * @endcode |
| 38 | + */ |
| 39 | +function next_post_update_remove_automatic_cors() { |
| 40 | + \Drupal::messenger()->addWarning(t('SECURITY UPDATE: The Next module no longer automatically enables CORS. If your Next.js site makes client-side API requests (useEffect, useSWR, etc.), you must configure CORS explicitly in services.yml. See the module\'s CORS.md file or <a href="@url">Drupal CORS documentation</a> for details.', [ |
| 41 | + '@url' => 'https://www.drupal.org/node/2715637', |
| 42 | + ])); |
| 43 | +} |
0 commit comments