{"title":"Cosaint clickjacking","version":"6.1","locale":"ga","docname":"ref/clickjacking","url":"/ga/6.1/ref/clickjacking/","canonical":"https://djangodocs.dev/ga/6.1/ref/clickjacking/","summary":"The clickjacking middleware and decorators provide easy-to-use protection against clickjacking.","html":"<span id=\"clickjacking-protection\"></span><h1>Cosaint clickjacking<a class=\"heading-anchor\" href=\"#module-django.middleware.clickjacking\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>The clickjacking middleware and decorators provide easy-to-use protection\nagainst <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Clickjacking\">clickjacking</a>. This type of attack occurs when a malicious site\ntricks a user into clicking on a concealed element of another site which they\nhave loaded in a hidden frame or iframe.</p>\n<section id=\"an-example-of-clickjacking\">\n<h2>Sampla de clickjacking<a class=\"heading-anchor\" href=\"#an-example-of-clickjacking\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Suppose an online store has a page where a logged-in user can click &quot;Buy Now&quot;\nto purchase an item. A user has chosen to stay logged into the store all the\ntime for convenience. An attacker site might create an &quot;I Like Ponies&quot; button\non one of their own pages, and load the store's page in a transparent iframe\nsuch that the &quot;Buy Now&quot; button is invisibly overlaid on the &quot;I Like Ponies&quot;\nbutton. If the user visits the attacker's site, clicking &quot;I Like Ponies&quot; will\ncause an inadvertent click on the &quot;Buy Now&quot; button and an unknowing purchase of\nthe item.</p>\n</section>\n<section id=\"preventing-clickjacking\">\n<span id=\"clickjacking-prevention\"></span><h2>Clickjacking a chosc<a class=\"heading-anchor\" href=\"#preventing-clickjacking\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Tugann brabhsálaí nua-aimseartha onóir ar cheanntásc HTTP <a class=\"reference external\" href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options\">X-Frame-Options</a> a thugann le fios an bhfuil cead ag acmhainn luchtú laistigh de fhráma nó iframe nó nach bhfuil. Má tá an ceannteideal sa fhreagra le luach <code class=\"docutils literal notranslate\">SAMEORIGIN</code> ansin ní luchtálfaidh an brabhsálaí an acmhainn i bhfráma ach amháin má tháinig an t-iarratas ón suíomh céanna. Má tá an ceannteideal socraithe go DENY` ansin cuirfidh an brabhsálaí bac ar an acmhainn ó luchtú i bhfráma is cuma cén suíomh a rinne an iarraidh.</p>\n<p>Soláthraíonn Django cúpla bealach chun an ceannteideal seo a áireamh i bhfreagraí ó do shuíomh:</p>\n<ol class=\"arabic simple\">\n<li><p>Middleware a shocraíonn an ceanntásc i ngach freagra.</p></li>\n<li><p>Sraith maisitheoirí radhairc is féidir a úsáid chun an lár-earraí a shárú nó chun an ceanntásc a shocrú ach le haghaidh tuairimí áirithe.</p></li>\n</ol>\n<p>Ní shocróidh an ceannteideal HTTP <code class=\"docutils literal notranslate\">X-Frame-Options</code> ach ag na maisitheoirí meán-earraí nó amharc mura bhfuil sé i láthair sa fhreagra cheana féin.</p>\n</section>\n<section id=\"how-to-use-it\">\n<h2>Conas é a úsáid<a class=\"heading-anchor\" href=\"#how-to-use-it\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"setting-x-frame-options-for-all-responses\">\n<h3>Socrú <code class=\"docutils literal notranslate\">Roghanna X-Frame</code> do gach freagra<a class=\"heading-anchor\" href=\"#setting-x-frame-options-for-all-responses\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Chun an luach céanna <code class=\"docutils literal notranslate\">X-Frame-Options</code> a shocrú do gach freagra ar do shuíomh, cuir <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>django.middleware.clickjacking.xframeOptionsMiddleware'` chuig:setting: MIDDLEWARE:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MIDDLEWARE <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;django.middleware.clickjacking.XFrameOptionsMiddleware&quot;</span><span class=\"p\">,</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Tá an láithreán gréasáin seo cumasaithe sa chomhad socruithe a ghineann: djadmin: startproject.</p>\n<p>De réir réamhshocraithe, socraíonn an middleware an ceannteideal <code class=\"docutils literal notranslate\">X-Frame-Options</code> go DENY` do gach HttpResponse` atá ag imeacht. Más mian leat aon luach eile don cheanntásc seo ina ionad sin, socraigh an socrú: setting: X_FRAME_OPTIONS:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>X_FRAME_OPTIONS <span class=\"o\">=</span> <span class=\"s2\">&quot;SAMEORIGIN&quot;</span>\n</code></pre></div>\n<p>Agus an middleware á úsáid agat d'fhéadfadh go mbeadh roinnt tuairimí ann nuair nach dteastaíonn uait** an tacar ceanntásc <code class=\"docutils literal notranslate\">X-Frame-Options</code> ag teastáil uait. Maidir leis na cásanna sin, is féidir leat maisitheoir amharc a úsáid a insíonn don middleware gan an ceannteideal a shocrú:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.decorators.clickjacking</span> <span class=\"kn\">import</span> xframe_options_exempt\n\n\n<span class=\"nd\">@xframe_options_exempt</span>\n<span class=\"k\">def</span> <span class=\"nf\">ok_to_load_in_a_frame</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;This page is safe to load in a frame on any site.&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Más mian leat foirm a chur isteach nó rochtain a fháil ar fhianán seisiúin laistigh de fhráma nó iframe, b'fhéidir go mbeidh ort socruithe: :setting: CSRF_COOKIE_SAMESITE nó:setting: SESSION_COOKIE_SAMESITE a mhodhnú.</p>\n</aside>\n</section>\n<section id=\"setting-x-frame-options-per-view\">\n<h3>Socrú <code class=\"docutils literal notranslate\">Roghanna Fráma X-</code> in aghaidh an amharc<a class=\"heading-anchor\" href=\"#setting-x-frame-options-per-view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Chun an ceanntásc <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>X-Frame-Options` a shocrú ar bhonn in aghaidh an amharc, soláthraíonn Django na maisiúcháin seo:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.decorators.clickjacking</span> <span class=\"kn\">import</span> xframe_options_deny\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.decorators.clickjacking</span> <span class=\"kn\">import</span> xframe_options_sameorigin\n\n\n<span class=\"nd\">@xframe_options_deny</span>\n<span class=\"k\">def</span> <span class=\"nf\">view_one</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;I won&#39;t display in any frame!&quot;</span><span class=\"p\">)</span>\n\n\n<span class=\"nd\">@xframe_options_sameorigin</span>\n<span class=\"k\">def</span> <span class=\"nf\">view_two</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;Display in a frame if it&#39;s from the same origin as me.&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Tabhair faoi deara gur féidir leat na maisitheoirí a úsáid i gcomhar leis an middleware. Sáraíonn úsáid maisitheora an mheán-earraí.</p>\n</section>\n</section>\n<section id=\"limitations\">\n<h2>Teorainneacha<a class=\"heading-anchor\" href=\"#limitations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Ní chosnóidh an ceannteideal X-Frame-Options` ach ar chliceacáil i <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>brabhsálaí nua-aimsearta'.</p>\n</section>","rootId":"module-django.middleware.clickjacking","toc":[{"title":"Sampla de clickjacking","anchor":"an-example-of-clickjacking","children":[]},{"title":"Clickjacking a chosc","anchor":"preventing-clickjacking","children":[]},{"title":"Conas é a úsáid","anchor":"how-to-use-it","children":[{"title":"Socrú Roghanna X-Frame do gach freagra","anchor":"setting-x-frame-options-for-all-responses","children":[]},{"title":"Socrú Roghanna Fráma X- in aghaidh an amharc","anchor":"setting-x-frame-options-per-view","children":[]}]},{"title":"Teorainneacha","anchor":"limitations","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"Tagairt API","url":"/ga/6.1/ref/"}],"prev":{"docname":"ref/class-based-views/flattened-index","title":"Tuairimí cineálacha rang-bhunaithe - innéacs comhréadaithe","url":"/ga/6.1/ref/class-based-views/flattened-index/"},"next":{"docname":"ref/contrib/index","title":"Pacáistí contrib","url":"/ga/6.1/ref/contrib/"},"formats":{"html":"/ga/6.1/ref/clickjacking/","markdown":"/ga/6.1/ref/clickjacking.md","json":"/ga/6.1/ref/clickjacking.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/ref/clickjacking.txt","official":"https://docs.djangoproject.com/ga/6.1/ref/clickjacking/","inVersions":["6.1","6.0","5.2"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}