Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7051631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:17:12+00:00 2026-05-28T03:17:12+00:00

I know how the cookies work, just started to dig why Codeigniter does not

  • 0

I know how the cookies work, just started to dig why Codeigniter does not store generated csrf token in SESSION, it just store in cookie. Concerned about security, I’v started to think about php setcookie() function params such as path and domain. And I have asked myself is it possible to set ‘evil_cookie’ with a path=’/’ and domain = ‘www.goodsite.com’ from another domain, from some ‘www.evilsite.com’? And another question is, will ‘evil_cookie’ be sent to ‘www.goodsite.com’ when performing request to ‘www.goodsite.com’?

So, I did a test. I’v created ‘set_cookie.php’ file and uploaded it to some ‘www.evilsite.com’:

setcookie('evil_cookie', 'gotcha', time() + 60 * 30, '/', 'www.goodsite.com');

I was using Firefox and Firebug + Cookie plugins for viewing sent and received cookies. So, I did receive ‘evil_cookie’ after the request to ‘www.evilsite.com/set_cookie.php’. However, the cookie was not saved (at least there was no such cookie when viewing in firebug cookie plugin panel). Nor it was sent when requesting again to “www.evilsite.com/set_cookie.php”. Just received but not saved.

From the Firefox browser point of view, it’s logical and secure to save cookie for current domain only. IMHO those set cookie() params such as path and domain are primarily for managing cookies for current domain and its subdomains but not for external domains. I was a little bit upset I was unable to find related info on php.net, so I’m not sure is it a browser related behavior and specifics how it deals with “3rd party cookies” or it’s more a standard? Does all browsers behave the same? If there’s any solid and reliable source for such statements please share.

That is also relevant to another use of cookies – store session data (without using PHP native sessions, for example Codeigniter does so). So, if all browsers do not allow to safe cookie with other than current domain then It’s OK. However, it does not protect from CSRF as ‘www.evilsite.com’ might contain evil javascript code that will create ‘evil_cookie’ directly on the client when a user will perform and get a request from ‘www.evilsite.com’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:17:12+00:00Added an answer on May 28, 2026 at 3:17 am

    […] is it possible to set ‘evil_cookie’ with a path=’/’ and domain = ‘www.goodsite.com’ from another domain, from some ‘www.evilsite.com’?

    No, user agents should ignore Set-Cookie directives with Domain attributes that do not domain-match the current requested domain:

    The user agent will reject cookies unless the Domain attribute
    specifies a scope for the cookie that would include the origin
    server. For example, the user agent will accept a cookie with a
    Domain attribute of "example.com" or of "foo.example.com" from
    foo.example.com, but the user agent will not accept a cookie with a
    Domain attribute of "bar.example.com" or of "baz.foo.example.com".

    Such cookies would not even be accepted by user agents. Similar applies to the Path and Secure attributes.

    See also How do browser cookie domains work? for examples of how the Domain attribute values are interpreted by user agents.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not great at PHP, and everything I currently know, I have just taught
Well, I just started to work on server side scripting , I chose PHP,
I'm learning how to work with cookies in Ruby on Rails. All I know
First off, I'm not all that familiar with cookies but I know how they
I know this is usually done with cookies, but I am getting unpredictable results
Anyone know how I can use httponly cookies for sessions and cookies on the
I know from this question that Firefox 3.0 and up stores its cookies in
I know that I can set expiration date for a cookie, but can I
Due to weird domain/subdomain cookie issues that I'm getting, I'd like to know how
I just enabled Session in my Google AppEngine/Java + GWT application. And how do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.