Software⏱️ 2 min read📅 2026-05-31

How to Fix: Uncaught Error: SECURITY_ERR: DOM Exception 18 when I try to set a cookie

SECURITY_ERR: DOM Exception 18 occurs when a script tries to set a cookie with an invalid or missing domain. Check the domain and port number in your cookie settings.

Quick Answer: Verify that the domain and port number in your cookie settings are correct and properly formatted.

The error you're encountering, 'SECURITY_ERR: DOM Exception 18', occurs when the browser's same-origin policy is violated. This happens when attempting to set a cookie that originates from a different domain than the current webpage.

🛑 Root Causes of the Error

  • Using a cookie plugin that doesn't properly handle cross-origin requests.

🛠️ Step-by-Step Verified Fixes

Method 1: Using a JSONP-based Cookie Plugin

  1. Step 1: Choose a cookie plugin that supports JSONP, such as jQuery Cookie.

Method 2: Setting Cookies on the Server-side

  1. Step 1: Set up your server to handle cookie requests, using a framework like Node.js or Django.

✨ Wrapping Up

To resolve this issue, ensure your chosen cookie plugin is compatible with cross-origin requests and consider setting cookies on the server-side for added security.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions