{
    "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors",
    "locale": "en",
    "title": "HTTP headers: security, caching and CORS · DeLaParra Services",
    "description": "What HTTP headers are, which security headers every site needs, how caching works with Cache-Control and ETag, and how to configure CORS correctly in Laravel.",
    "alternates": {
        "en": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors",
        "nl": "https://delaparra-services.nl/nl/handleidingen/http-headers-beveiliging-caching-en-cors"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.csv",
        "md": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.md",
        "json": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.json",
        "zip": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.zip",
        "pdf": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.csv",
            "encodingFormat": "text/csv",
            "name": "http-headers-beveiliging-caching-en-cors.csv"
        },
        {
            "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.json",
            "encodingFormat": "application/json",
            "name": "http-headers-beveiliging-caching-en-cors.json"
        },
        {
            "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.md",
            "encodingFormat": "text/markdown",
            "name": "http-headers-beveiliging-caching-en-cors.md"
        },
        {
            "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.pdf",
            "encodingFormat": "application/pdf",
            "name": "http-headers-beveiliging-caching-en-cors.pdf"
        },
        {
            "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.zip",
            "encodingFormat": "application/zip",
            "name": "http-headers-beveiliging-caching-en-cors.zip"
        }
    ],
    "markdown": "# HTTP headers: security, caching and CORS\n\nWith every request and every response, the browser or server sends **headers**: extra lines containing information about the message. You can’t see them on the page, but they determine a great deal: whether your site is secure, whether it loads quickly, and whether your API is accessible from outside.\n\n## View headers\n\n- **Browser:** F12 → Network → click on a request → Headers.\n- **Terminal:** `curl -sI https://jouwsite.nl`\n\n## Headers sent by the browser\n\n| Header | Meaning |\n|---|---|\n| `Accept` | The format the browser requires (`application/json`, `text/html`) |\n| `Accept-Language` | Preferred language |\n| `Accept-Encoding` | The compression formats the browser supports (gzip, br) |\n| `Authorization` | Login details or token (`Bearer …`) |\n| `Cookie` | Cookies, such as your session |\n| `Origin` / `Referer` | The site from which the request originates |\n| `User-Agent` | Which browser or tool |\n| `If-None-Match` / `If-Modified-Since` | \"I already have a version; is there anything new?\" |\n| `Range` | Only part of a file |\n\n## Security headers that every website needs\n\n| Header | Recommended | Protects against |\n|---|---|---|\n| `Strict-Transport-Security` | `max-age=31536000; includeSubDomains` | Unsecured HTTP connections |\n| `Content-Security-Policy` | Start with a strict ‘report-only’ policy | Malicious scripts (XSS) |\n| `X-Content-Type-Options` | `nosniff` | Files that are executed as something else |\n| `X-Frame-Options` | `SAMEORIGIN` | Loading your site in a hidden frame (clickjacking) |\n| `Referrer-Policy` | `strict-origin-when-cross-origin` | Leakage of URLs to other sites |\n| `Permissions-Policy` | `camera=(), microphone=(), geolocation=()` | Unauthorised use of device functions |\n\nFirst, set a **Content-Security-Policy** to `Content-Security-Policy-Report-Only` mode. That way, you can see what might break without your site breaking.\n\nYou should also remove any headers that reveal which software you’re running, such as `X-Powered-By: PHP/8.3`.\n\n## Setting up cookies securely\n\nA session cookie should have the following characteristics:\n\n- `Secure`: via HTTPS only\n- `HttpOnly`: JavaScript cannot read it\n- `SameSite=Lax`: not sent by other sites in the event of suspicious requests\n\nIn Laravel: `SESSION_SECURE_COOKIE=true` in your `.env` file.\n\n## Caching: speed\n\n| Header | What it does |\n|---|---|\n| `Cache-Control` | How long something may be retained and by whom |\n| `ETag` | A ‘fingerprint’ of the content |\n| `Last-Modified` | When the content was last modified |\n| `Expires` | Obsolete version of `max-age` |\n| `Vary` | The answer varies depending on … (e.g. language or Origin) |\n\nRules of thumb:\n\n- **CSS/JS files with a hash in their name** (`app.3f9a.js`, as generated by Vite): `public, max-age=31536000, immutable`.\n- **HTML pages:** `no-cache` (the browser checks every time to see if there’s anything new; with ETag, this is quick).\n- **Personal data:** `private, no-store`.\n\nIf the content has not changed, the server responds with **304 Not Modified** and the browser does not need to download anything again.\n\n## CORS: who is allowed to use your API?\n\nBy default, a browser blocks requests from site A to an API on domain B. Using **CORS headers**, the API grants permission:\n\n| Header | Meaning |\n|---|---|\n| `Access-Control-Allow-Origin` | Which site(s) are permitted |\n| `Access-Control-Allow-Methods` | Which methods (GET, POST…) |\n| `Access-Control-Allow-Headers` | Which headers the request is permitted to contain |\n| `Access-Control-Allow-Credentials` | Whether cookies are permitted |\n| `Access-Control-Max-Age` | How long the browser retains the consent |\n\nIn Laravel, you configure this via `config/cors.php`:\n\n```php\n'paths' => ['api/*', 'sanctum/csrf-cookie'],\n'allowed_origins' => ['https://app.jouwdomein.nl'],\n'supports_credentials' => true,\n```\n\n**Never** use `*` in conjunction with logging in or cookies.\n\n## Other headers you may come across\n\n`Content-Type` (response format), `Content-Length` (size), `Location` (redirect destination), `Set-Cookie`, `WWW-Authenticate` (for 401), `Retry-After` and `X-RateLimit-*` (for 429).\n\n## Need help?\n\nWould you like to know whether your site is sending the correct security headers? I’ll check this as part of the **AI code review**. A new, secure site falls under **Web design and development**.\n\n## Skills\n\n- [HTTP headers review] (/nl/skills/http-headers-review)\n- [Chrome DevTools Agent] (/nl/skills/chrome-devtools)\n- [Laravel OWASP Security] (/nl/skills/laravel-owasp-security)\n- [API Design Principles] (/nl/skills/api-design-principles)\n\n## Related services\n\n- [Webdesign en -ontwikkeling] (/nl/services#service-01)\n- [Beoordeling van AI-code] (/nl/services#service-05)\n\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "TechArticle",
                "@id": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors#article",
                "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors",
                "headline": "HTTP headers: security, caching and CORS",
                "description": "What HTTP headers are, which security headers every site needs, how caching works with Cache-Control and ETag, and how to configure CORS correctly in Laravel.",
                "inLanguage": "en",
                "subjectOf": {
                    "@id": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors#dataset"
                }
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors#dataset",
                "name": "HTTP headers: security, caching and CORS",
                "description": "What HTTP headers are, which security headers every site needs, how caching works with Cache-Control and ETag, and how to configure CORS correctly in Laravel.",
                "url": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors",
                "identifier": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors#article"
                },
                "publisher": {
                    "@type": "Organization",
                    "name": "DeLaParra Services",
                    "url": "https://delaparra-services.nl/"
                },
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/manuals#dataset",
                    "name": "Manuals for working on your own app",
                    "url": "https://delaparra-services.nl/manuals"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "http-headers-beveiliging-caching-en-cors.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.csv",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "http-headers-beveiliging-caching-en-cors.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.json",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "http-headers-beveiliging-caching-en-cors.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.md",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "http-headers-beveiliging-caching-en-cors.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.pdf",
                        "inLanguage": "en"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "http-headers-beveiliging-caching-en-cors.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/manuals/http-headers-beveiliging-caching-en-cors.zip",
                        "inLanguage": "en"
                    }
                ]
            }
        ]
    }
}