<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Agnieszka Pietruczuk on Medium]]></title>
        <description><![CDATA[Stories by Agnieszka Pietruczuk on Medium]]></description>
        <link>https://medium.com/@aa.pietruczuk?source=rss-5f09697279a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*RkDMk-95gZgud8-dVJf04Q.jpeg</url>
            <title>Stories by Agnieszka Pietruczuk on Medium</title>
            <link>https://medium.com/@aa.pietruczuk?source=rss-5f09697279a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:51:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aa.pietruczuk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[1500$ bounty: how unprotected directory leaked sensitive info]]></title>
            <link>https://medium.com/@aa.pietruczuk/1500-bounty-how-unprotected-directory-leaked-sensitive-info-929b55515232?source=rss-5f09697279a------2</link>
            <guid isPermaLink="false">https://medium.com/p/929b55515232</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[Agnieszka Pietruczuk]]></dc:creator>
            <pubDate>Wed, 01 May 2024 11:44:58 GMT</pubDate>
            <atom:updated>2024-05-01T11:44:58.860Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*F9isiNNG9vFWuytmrygAlw.jpeg" /><figcaption><a href="https://www.flickr.com/photos/g4ll4is/with/8519038019">g4ll4is</a></figcaption></figure><p>I found this bug almost by accident. It wasn’t a program I knew or spent more time with but around New Year’s Eve I found a pre account takeover vulnerability on it (<a href="https://medium.com/@aa.pietruczuk/account-pre-hijacking-using-auto-login-token-94ad3da7f3d6">similar to this one</a>) and it turned out to be a duplicate:(</p><p>So I was just looking around for some low hanging fruits and I noticed an interesting photo url. The format was something like:</p><p><a href="https://program.com/photos/111/222.jpg">https://program.com/photos/111/222.jpg</a></p><p>So it drew my attention for two reasons:</p><ul><li>the image id seems iterable</li><li>there is no token or key protecting this asset</li></ul><p>But it was a public subdomain with some educational stuff and it could just be public. I iterated by several ids manually and I found immediately some photos that looked more private than the ones in public articles. It also appeared that there is <strong>a lot </strong>of images in the folder.</p><p>I was ready to give up but a friend of mine iterated through more photos and we developed some theories. The data seemed to be connected with different feature which definitely shouldn’t be public. Also we discovered there are several similar collections and they all seem to have protection. I found the one that was left behind. It also seemed to store all the images from this service.</p><p>I reported the bug and it was immediately confirmed and after a while it was fixed.</p><p><strong>The lessons from this vulnerability</strong></p><ul><li>Iterated ids in this kind of storage is not a good idea; in case of a fuckup at least the random ids would give some protection</li><li>Storages for public and sensitive assets should be separated; they require different type of protections</li><li>If possible, access to the private images should require login. If not possible (external storage), it should be protected with token or key</li><li>Some monitoring system could be added to have visibility over the endpoints and detect cases of attackers iterating through thousands of photos</li></ul><p><strong>Bonus</strong>:</p><ul><li>If you develop an application with chat or some sharing capability — be sure users are aware of the risk. If they regularly put sensitive assets in the chat, it’s definitely the product’s responsibility to protect their privacy and security.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=929b55515232" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Account pre-hijacking using auto login token]]></title>
            <link>https://medium.com/@aa.pietruczuk/account-pre-hijacking-using-auto-login-token-94ad3da7f3d6?source=rss-5f09697279a------2</link>
            <guid isPermaLink="false">https://medium.com/p/94ad3da7f3d6</guid>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[infosec-write-ups]]></category>
            <dc:creator><![CDATA[Agnieszka Pietruczuk]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 18:16:44 GMT</pubDate>
            <atom:updated>2023-10-31T18:16:44.339Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I was testing a new app named Redacted.</p><p>I focused on account management as this is something I work on a lot as a defender.</p><p>The first thing you need to know is that this app <strong>doesn’t have email verification</strong>. Well, it is there but it’s not required. This setup is always hazardous because of users creating accounts with mistyped emails. And of course, pre-account takeover.</p><p>The first time I heard about pre-account takeover was in this <a href="https://hbothra22.medium.com/attacking-social-logins-pre-authentication-account-takeover-790248cfdc3">medium post </a>, but I can see now Wikipedia has <a href="https://en.wikipedia.org/wiki/Account_pre-hijacking">brand new page</a> about it and they use the term “account pre-hijacking”.</p><p>The idea behind this attack is simple: an attacker creates an account<strong> before the victim registers</strong>. Then after the victim recovers the account (usually with remind password flow), the attacker still has access. This persistence can be achieved in a couple of ways but there is one practice that companies can always use to eliminate the attack: email verification during registration.</p><p>So, I can create an account for the email I’m not an owner of. Although probably the owner will get the welcome email, they will most likely mark it as spam.</p><p>In the original post the idea was that the victim will register with social login instead of resetting the password. So the password set by the attacker will never be changed. This way both, the victim and attacker will have access to the account at the same time.</p><p>I did this once in another application and it worked perfectly:</p><ul><li>I knew someone will be joining a company as an employee</li><li>I created account using this person’s email (at that point the email probably didn’t even exist, but even if it did, probably a new employee will just assume someone created account on the service for him)</li><li>I was checking the account every day and after a few days he logged in with social login and I still had access</li></ul><h3><strong>The vulnerability — legacy token on a signup page</strong></h3><p>At first I was not thinking about this type of vulnerability because there was no social login. But then, I noticed something interesting,</p><p><a href="https://sso.redacted.com/login/xyz">https://sso.redacted.com/login/xyz</a></p><p>The website was using a single sign-on for authentication. However the registration form I used was not the default one. I found a form on one of the subdomains and I registered with it. It means that the account and the session was created on<a href="https://app.redacted.com/"> https://app.redacted.com</a> and not the SSO. To not force me to login again, they used an auto login token. It’s pretty standard in this situation but usually this kind of token should have a very limited lifetime.</p><p>This auto login url should take me to another page to login and it should expire. It should take 5 seconds. Just to be safe, we can keep it alive for 5 minutes. But after some testing I realized, not only the token is not expiring, it can be used multiple times. There is no need for that.</p><p>So I thought — what if it’s some obscure mechanism nobody remembers and it’s not even revoked after password change?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FMofCMnBw0Sq3tAnjGB%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExa3Jycm5kOXFmYnk2a3Vlb21mZHZuY2d4dGlpMzdxdXI0OGVmdGp3eCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FMofCMnBw0Sq3tAnjGB%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FMofCMnBw0Sq3tAnjGB%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dba07d6e59bab6f94095598863987c9/href">https://medium.com/media/2dba07d6e59bab6f94095598863987c9/href</a></iframe><p>Revoking access after password change (or remind password mechanism) is crucial even without pre-access vulnerabilities. <strong>If the user is hacked</strong>, their password leaked, a computer was stolen or a former partner took over the account, this is what is advised: reset access to your account by changing password. The sessions will be revoked, the access tokens removed and whoever had access to the account should be kicked off. Checking all the account settings is always welcomed, because the attacker could have changed the phone or some other crucial information.</p><p>So I kept the token and did what a confused new user would do: I clicked “I forgot my password” on the login screen and I changed the password.</p><p>And the token still worked! In fact it worked for a couple of weeks, so I assume there was no revoking mechanism for those. There was a lot of sensitive data on that app, so after a while I could have info about financial data of the victim. Although I wouldn’t be able to change email or bank account info because I didn’t know the password.</p><h3><strong>A recap — 5 minor issues</strong></h3><p>So, a recap about the existing bugs or misconfigurations:</p><ol><li>Email verification not required to create account</li><li>Auto login token can be used multiple times</li><li>Auto login token can be used for weeks instead of few minutes</li><li>Auto login token not revoked on account recovery</li></ol><p>But what if I would try to take over the account of someone more security aware? Those are after all sensitive data, so we have the ability to setup the MFA, additional login protection. That has to help, right? Well…</p><p>5. Auto login token bypasses the MFA</p><h3><strong>Is it really that serious?</strong></h3><p>I was reading before that some bug bounty programs don’t accept this vulnerability. It is of course their decision, but I have to wonder about the attack vector.</p><p>The first argument could be that the attack is based on <strong>social engineering</strong>. But that’s not really a case here because the victim does nothing wrong, there is no error, no action that could be avoided by a more aware person. Even if the user will write to customer support with questions, in most cases they will tag it as an accident and ask them to use recovery flow. Even if the victim is paranoid and will set up MFA just to be sure (in this case), it won’t help. The only real solution here would be to recover the account, delete it and register again. I would probably do it, but I can be the exception.</p><p>So if it’s not social engineering, someone could say it is pretty difficult to exploit because you need to know the email address of the victim. Some people suggest to mass register plenty of accounts and just wait for luck. It can be successful especially if the target is very specific (portal for chefs, business owners, doctors) but I see it more like a targeted attack. I could know the victim or overheard that a co-worker is thinking about registering on this service. So it would be a targeted attack but it doesn’t make it less important. Only I should have access to my account and I should always be able to revoke the access to it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94ad3da7f3d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improper error handling leads to exposing internal tokens]]></title>
            <link>https://medium.com/@aa.pietruczuk/improper-error-handling-leads-to-exposing-internal-tokens-3355d6b43a32?source=rss-5f09697279a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3355d6b43a32</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Agnieszka Pietruczuk]]></dc:creator>
            <pubDate>Mon, 28 Nov 2022 21:48:51 GMT</pubDate>
            <atom:updated>2022-11-28T21:48:51.291Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I started using a new application for secret management. Let the name be [redacted].</p><p>I often try to poke around the app just to see if I find any obvious errors. When I tried to access the API without Authorization header one thing caught my attention. The “stack” property was appended to the response body.</p><pre>{<br>&quot;status&quot;: 401,<br>&quot;errorCode&quot;: &quot;&quot;,<br>&quot;errorClass&quot;: &quot;NotAuthenticated&quot;,<br>&quot;stack&quot;: &quot;NotAuthenticated\n at /usr/src/app/lib/services/userService.js:56:15\n at Generator.throw (&lt;anonymous&gt;)\n at rejected (/usr/src/app/lib/services/userService.js:6:65)\n at runMicrotasks (&lt;anonymous&gt;)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)&quot;<br>}</pre><p>This is usually a bad sign. It’s already showing me a path to the application and the functions names are leaking info about used libraries and sometimes their versions. Also the info in error messages will help attackers use undocumented API.</p><p>But it didn’t give me much more to work with. I was trying to cause more crashes and see if there’s anything interesting. The database error would be a good match but the input validation was pretty solid.</p><p>I tried to test for SQL injection but I was getting a Bad Request response with warnings about illegal characters. And then something unexpected happened. My request passed the backend validation and returned a new type of bug. It was something like this:</p><pre>{<br>&quot;error&quot;: {<br>&quot;response&quot;: {<br>&quot;config&quot;: {<br>&quot;url&quot;: &quot;https://admin.googleapis.com/admin/directory/v1/users?query=x%40y.com%22%2BOR%2B1%3D1--&amp;maxResults=500&amp;domain=y.com&quot;,<br>&quot;method&quot;: &quot;GET&quot;,<br>&quot;userAgentDirectives&quot;: [<br>{<br>}<br>],<br>&quot;headers&quot;: {}</pre><p>The backend was sending requests to Google APIs to fetch more data about the user. Google responded with 400 code that was not handled by the application. The whole error was dumped with response and request headers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/0*hgtdGwQvDeTHGQwL" /><figcaption>Authorization header!</figcaption></figure><p>At first I thought they used my token, but they actually had a backend token for internal communication. This one had additional scopes: admin.directory.user.security.</p><p>I validated the token in Google’s token_info endpoint, it allowed me to fetch info about all users and groups in this domain.</p><p>I was aware that the application uses another Google service with much more sensitive information. Unfortunately after trying to break the endpoints that were using this functionality I hit the wall.</p><p>I reported the bug and the new version was fixed in a few hours. Stack trace was removed along with errors dumped on Bad Request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*pQJrDYq_33FI_5rxNbJkPA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3355d6b43a32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cookies for beginners: Ł to Z (Part 2)]]></title>
            <link>https://medium.com/docplanner-tech/cookies-for-beginners-%C5%82-to-z-part-2-c2def23c9a22?source=rss-5f09697279a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2def23c9a22</guid>
            <category><![CDATA[cookies]]></category>
            <category><![CDATA[it]]></category>
            <category><![CDATA[cooking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Agnieszka Pietruczuk]]></dc:creator>
            <pubDate>Mon, 11 Mar 2019 14:32:26 GMT</pubDate>
            <atom:updated>2023-11-30T20:35:16.663Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cookies for beginners (Part 2)</h3><p>In the <a href="https://medium.com/docplanner-tech/cookies-for-beginners-a-to-%C5%82-part-1-27fd40256793">first part</a> of this cookies series, I focused mostly on the scope of the cookies. Now we move on to additional flags that can help in securing the most important cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*brK9AREoaJ-ToiwJda4cfQ.jpeg" /><figcaption>Photo: <a href="https://thoughtcatalog.com/">ThoughtCatalog</a></figcaption></figure><h3>How long will the cookie last?</h3><p>In general, cookies can be divided into 2 types: persistent and session (note that “session cookie” has two meanings). The latter is created when the developer sends a cookie without the lifetime parameter. This means that the cookie will live only as long as the browser session. Usually that means to the moment user closes browser but if he uses session restoring (tabs are restored from history after reopening browser), session cookies can last much longer.</p><p>As a lifetime parameter you can use Max-Age or Expires flags. Max-Age requires a number of seconds and Expires operates on the timestamp. In the browser both are converted to date:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/0*7ECDj-JsrlkeqJNL" /></figure><p>The first one is the session cookie — datetime is set before Unix time.</p><p>Flag Max-Age was added later and some older browsers can ignore it. Also, in the case of adding both flags, in modern browsers only Max-Age will be taken into consideration.</p><h3>HttpOnly flag</h3><p>As I mentioned in the first part of the article, cookies can be set using HTTP header or with Javascript. An example of using the second method would be:</p><p>document.cookie = “cookie=value; expires=Thu, 22 Dec 2019 12:00:00 UTC; path=/”;</p><p>In many cases, the ability to set and read cookies with Javascript is crucial. In some, for example in the case of session cookies, they will be probably always handled by HTTP protocol. Additionally, those cookies can be very sensitive and removing this attack vector will make the website more secure. Of course, if you have XSS vulnerability in your application, it’s already bad. Nevertheless the ability for the attacker to just copy a session cookie would even worse.</p><p>HttpOnly flag was introduced by Microsoft and at first it was used only in the Internet Explorer. Later, this flag became standard. The correct syntax requires just one word:</p><p>Set-Cookie: cookie=value; HttpOnly</p><p>You can check how this flag works in practice quite easily: open the cookies tab in the browser, find those values with HttpOnly set to 1 and type document.cookie in the console. It should only show you cookies without this specific flag.</p><p>You can’t neither read nor write HttpOnly cookies with Javascript. You can, however, overwrite them to other values.</p><p><strong>What if you send XMLHttpRequest and the response contains the “Set-Cookie” header?</strong> Will it allow Javascript to read all cookies? Actually it won’t —the header will be respected by the browser but it’s not possible for Javascript to read its content using the getAllResponseHeaders method (this one was a bug in earlier implementations of HttpOnly flag). Still, all cookies, including HttpOnly ones, will be sent with Ajax requests. Of course, only if the same-origin policy won’t block them.</p><p>The interesting bypass for this flag was using TRACK and TRACE methods. The attack worked by abusing the mechanism I just described, i.e., that all cookies are sent with Ajax calls. TRACE is a HTTP method that makes a server echo back the request. This behavior in combination with sending HttpOnly cookies will allow an attacker to see all cookies, even those that are not supposed to be visible for Javascript. This is called a cross-site tracing (XST) attack.</p><p>I wrote that this bypass “was” interesting — it is a really good example of hacker thinking out of the box, but this will no longer work in the modern browsers. The XMLHttpRequest doesn’t allow for TRACK/TRACE methods to be used and also it is now more common for servers to disable those HTTP headers.</p><h3>SameSite flag</h3><p>Most cookies flags have been at least several years in use. SameSite is different: Chrome introduced this feature in 2017, Firefox in the middle of 2018, and Safari shipped it with version 12, so only several months ago.</p><p>This flag is often described as the protection against CSRF attacks. That is correct to some extent — a cookie with the SameSite flag can’t be sent along with a cross origin request.</p><p>Why is that important? As you already know, cookies are used to authenticate users and<strong> once set cookie will be sent by the browser with every new request</strong>.</p><p>In the first part of the article I’ve described how loading one page can result in requesting multiple resources, many of which are hosted on other websites. Those are the so-called cross-site requests. They can be called using Ajax calls, simple links, or by embedding scripts/images.</p><p>With all that knowledge, the cross-site request forgery (CSRF) attack can be best explained with an example:</p><ol><li>A user is opening a link in a — looking totally legit and safe looking — email (“you won 10000$!”).</li><li>He enters a malicious website.</li><li>The malicious website automatically sends a POST request to <a href="http://www.my-pokemon-collection.com/delete-account">www.my-pokemon-collection.com/delete-account</a>.</li><li>If the website doesn’t use any CSRF protection and the user is logged to Pokemon collection on the same browser, the account will be deleted.</li></ol><p>Why did this happen? Because the request was sent in the name of the user. It was signed with the user’s cookies credentials.</p><p>The only thing left to say now is that <strong>if the session cookie had had the SameSite flag set, the browser wouldn’t have sent it with this request </strong>:)</p><p>There are two possible values for SameSite flag:</p><ol><li>Lax is the default value. When set, it will inform the browser to send cookie with every “safe” request like clicking on hyperlink on the page or redirecting.</li><li>Strict will withhold the cookies for all the requests. That means that if the user comes to the website by just clicking a link on DuckDuckGo, if the session cookie has SameSite set for “strict”, he won’t be logged in.</li></ol><p>The syntax in contrast to HttpOnly will have value:</p><p>Set-Cookie: cookie=value; SameSite=strict</p><p>In the previous part I was mostly focused on domain scope. How does that work for SameSite cookies? What exactly is considered “same site”?</p><p>In the IETF’s Same-site Cookies draft it states:</p><p><em>“A request is “same-site” if its target’s URI’s origin’s registrable domain is an exact match for the request’s initiator’s “site for cookies”, and “cross-site” otherwise.”</em></p><p>And the term registrable domain is explained in the other paragraph:</p><p><em>An origin’s “registrable domain” is the origin’s host’s public suffix plus the label to its left. That is, “https://www.example.com&quot;&#39;s registrable domain is “example.com”.</em></p><p>This means that in the context of cookies, the top level domain must be a match to be “same-site”. <strong>So even if the </strong><strong>SameSite cookie has scope that excludes subdomains, it will still be sent with all the requests from subdomains</strong>.</p><h3>Secure flag</h3><p>Cookies with the Secure flag can’t be sent if the request is not sent over the HTTPS protocol. It will be visible in HTTP headers and in document.cookie.</p><p>It can be set like HttpOnly flag, you have to add just one word:</p><p>Set-Cookie: cookie=value; Secure</p><p>It’s worth remembering that this cookie will be rejected if the developer wants to set it via not secured connection.</p><p>The interesting addition here is the fact that some browsers (I checked Google and Firefox) will respect the magic cookie name: <strong>if it starts with the prefix “__Secure”, it should have Secure flag</strong> <strong>added</strong>. If we will try to add this cookie without Secure flag, it will get rejected. It’s a nice feature if it is really crucial for the specific cookie to work only with SSL.</p><h3>Important stuff</h3><p>Remember that cookies are one of the most sensitive mechanisms in the browser. <strong>If an attacker is able to steal session cookies, he will be able to cause more damage than with your password</strong>. That’s because some websites have implemented additional protection for those cases. For example, two factor authentication or sending emails after “unusual login attempt”. With stolen cookies, all those actions won’t help.</p><p>If you have read my article and thought “that flag is not worth it, it’s not protecting my website fully”, remember that <strong>many attacks are based on not one but multiple different “small” vulnerabilities. </strong>The practice of creating many different defense mechanisms (you may know this rule as defense in depth principle) will be always beneficial.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2def23c9a22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docplanner-tech/cookies-for-beginners-%C5%82-to-z-part-2-c2def23c9a22">Cookies for beginners: Ł to Z (Part 2)</a> was originally published in <a href="https://medium.com/docplanner-tech">Docplanner Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cookies for beginners: A to Ł(Part 1)]]></title>
            <link>https://medium.com/docplanner-tech/cookies-for-beginners-a-to-%C5%82-part-1-27fd40256793?source=rss-5f09697279a------2</link>
            <guid isPermaLink="false">https://medium.com/p/27fd40256793</guid>
            <category><![CDATA[cooking]]></category>
            <category><![CDATA[docplannerit]]></category>
            <category><![CDATA[cookies]]></category>
            <category><![CDATA[it]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Agnieszka Pietruczuk]]></dc:creator>
            <pubDate>Mon, 28 Jan 2019 16:45:07 GMT</pubDate>
            <atom:updated>2023-11-30T20:34:56.205Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cookies for beginners (Part 1)</h3><p>Cookies are one of those topics that are equally important for developers and people that use computer mostly for their entertainment. Although it’s relatively hard to find movie scene with hackers talking about this part of the web, they are crucial not only for functioning of web application but also for many other areas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*qOPfiBryzRrHouW8" /><figcaption><a href="https://www.flickr.com/photos/opacity/">author:Opacity</a></figcaption></figure><p>They are commonly used for user tracking, which makes them part of privacy discussion. They enable developers to create state in HTTP protocols and are the most popular way to manage sessions.</p><p>But it’s not that common to dive into the inner workings of this mechanism. Too bad, because there are many great questions that could be asked in this matter. For instance, what are all those additional flags? What does it mean that cookie is secure? How do websites set cookies for other websites (yeah, that’s actually… never mind, keep reading)?</p><h3>How does it work?</h3><p>Ok, we will start small. Cookies can be sent by Javascript but they can also be part of the HTTP exchange. At the heart of it, it’s not some magic, just HTTP headers. Below you can see example of communication with the use of cookie headers.</p><p>Request:</p><pre>GET / HTTP/1.1</pre><pre>Host: tools.ietf.org</pre><pre>User-Agent: curl/7.54.0</pre><pre>Accept: */*</pre><p>Response:</p><pre>HTTP/1.1 200 OK</pre><pre>Date: Sat, 17 Nov 2018 20:18:17 GMT</pre><pre>X-Clacks-Overhead: GNU Terry Pratchett</pre><pre><strong>Set-Cookie: logged=true</strong></pre><p>Request after setting cookie:</p><pre>GET / HTTP/1.1</pre><pre>Host: tools.ietf.org</pre><pre>User-Agent: curl/7.54.0</pre><pre>Accept: */*</pre><pre><strong>Cookie: logged=true</strong></pre><p>This enables users to create some kind of state mechanism despite using stateless protocol. If the server will respond with some identifier, client will send it in every request. With this information, server can link the next requests with a specific user.</p><p>If you tried to browse web with curl without cookie engine it wouldn’t be a piece of cake. You would have to add cookie to the headers with every request that you send. The question is — which cookies should you send? How long should a specific cookie last? Which domain can see what cookies?</p><p>All those questions are crucial for “state management” to work properly. If you started sending your cookies to domains that didn’t set them, you would get hacked in no time. Thus browsers implement multiple mechanisms to secure this process. Besides the cookie’s name, value and original host there are additional flags that inform about the use of the particular cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zb5MYIw42xXBOfIg6qhPpw.png" /><figcaption>Cookies in Developers Tools</figcaption></figure><p>These are: domain, path, expires, secure, httponly, path and samesite.</p><h4>Rejecting cookies</h4><p>I will be using the term “rejecting” in the next paragraphes. In some cases when cookie lacks some properties or they are not correct, browser will change them to default values. In other cases, they can be rejected. The most obvious scenario would be trying to set cookie for different domain.</p><h3>Who wants a cookie? Domain and path flags</h3><p>There is one basic rule when handling cookies: you can only set and access them for the origin domain. So, why actually do we need the domain property? It’s because sometimes we want to specify if a cookie should be visible also for subdomains. But there is couple of rules to follow here.</p><p>If you don’t set domain and path flags, default values will be used. <strong>For path it’s the current one</strong>, not /. So if we are on /root route, this one will be used. This prevents the browser from sending cookies to /public route but not to /root/things.</p><p><strong>For </strong><strong>domain, the default value is the original host</strong>. For example, if you request <a href="https://ietf.org/">https://ietf.org</a>, you can get this kind of response (cookie header added by me):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*pM0_2C4BAaYsa15ZK2hoZw.png" /></figure><p>The domain is missing, so the cookie is set for the original host <strong>without dot </strong>in front of it. That means it’s not accessible for subdomains. In the browser, you will see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*u3TR4P_mKcehHpWgVXlk6g.png" /></figure><p>If the domain flag is passed (and it’s valid), the browser will always add a dot. That means that all subdomains will have access to the given cookie:</p><pre><a href="https://ietf.org/">https://ietf.org/</a></pre><pre>Set-cookie: cookie=value; path=/; domain=.<a href="http://ietf.org/">ietf.org</a></pre><pre>Set for domain „.<a href="http://ietf.org/">ietf.org</a>”</pre><pre>Visible for subdomains such as: <a href="https://tools.ietf.org/">https://tools.ietf.org</a><br></pre><pre><a href="https://ietf.org/">https://ietf.org/</a></pre><pre>Set-cookie: cookie=value; path=/; domain=<a href="http://ietf.org/">ietf.org</a></pre><pre>Set for domain  „.<a href="http://ietf.org/">ietf.org</a>”</pre><p>So allowing subdomains for accessing cookies requires nothing more than a proper domain value. Also <strong>in contrast to the same-origin policy</strong>, cookies ignore the port and scheme of the origin. This means that although you can’t (without proper CORS configuration) read the Ajax response from <a href="https://example.com:66/">http://example.com:66</a> to <a href="https://example.com/">https://example.com</a> or from <a href="https://subd.example.com/">https://subd.example.com</a> to <a href="https://subd.example.com/">https://example.com</a>, the cookies will be shared between them.</p><p>The root domain is allowed to set cookies that will be visible for all subdomains, but not for specific one. For subdomains the rule is similar - they can set cookies for all subdomains or only for themselves:</p><pre><a href="https://tools.ietf.org/html/rfc6265">https://tools.ietf.org/html/rfc6265</a></pre><pre>Set-cookie: cookie=value; domain=ietf.org</pre><pre>Set for domain „.<a href="http://ietf.org/">ietf.org</a>”</pre><pre><a href="https://tools.ietf.org/html/rfc6265">https://tools.ietf.org/html/rfc6265</a></pre><pre>Set-cookie: cookie=value;</pre><pre>Set for domain “tools.ietf.org”</pre><pre><a href="https://tools.ietf.org/html/rfc6265">https://tools.ietf.org/html/rfc6265</a></pre><pre>Set-cookie: cookie=value; domain=trustee.ietf.org/html; path=/</pre><pre>Rejected - trying to set from one subdomain to the other</pre><pre><a href="https://ietf.org/">https://ietf.org</a></pre><pre>Set-cookie: cookie=value; domain=<a href="http://trustee.ietf.org/html;path=/"> trustee.ietf.org/html;path=/</a></pre><pre>Rejected - trying to set from root to specific subdomain</pre><p>The cookie will also be rejected when the developer will try to set it to the top level domain. That’s because <strong>browsers don’t allow users to create “supercookies”</strong> that would be passed to every domain with given suffix. You can search top level domains on this list — <a href="https://publicsuffix.org/">https://publicsuffix.org</a>.</p><p>As you can see now, the domain flag in the cookie changes its scope. The interesting consequence of that is an inability to overwrite specific values:</p><pre><a href="https://ietf.org/">https://ietf.org</a></pre><pre>Set-cookie: a=with; domain=.ietf.org</pre><pre>Set-cookie: a=without</pre><pre>Both set, both sent with request (Cookie: a=with; a=without)</pre><p>Keep in mind that if you change the domain or path, you have to remove the old cookies first because the browser will send two versions of them and the order can be indeterministic. This doesn’t apply to the rest of the flags though.</p><p><strong>The most important thing regarding the </strong><strong>domain flag is to remember about setting it only for resources that need access to it.</strong> So if you have a big website with a lot of subdomains, ask yourself a question: do my subdomains need access to my session (or some other) cookie? If not, remember about setting it without dot. If you need to set some cookies only for moderators, you can always limit the path to /moderators.</p><h3>Third-party cookies</h3><p>Third-party cookies can be mistaken for “cross-domain” cookies. But it’s not the case. The rules for scope are exactly the same as for basic ones (one exception is samesite flag which will be covered in second part of this article). The difference actually lies in what the user sees.</p><p>If you enter <a href="https://www.youtube.com/">https://www.youtube.com</a> and you open the console, you can find the cookies storage confusing. In most browsers, on the left sidebar you will notice more than one page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*e_2RxM9_NHLPYvn2" /></figure><p>In the cookies panel, the domain attribute is set not only for the website that you are currently on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*BfGu09G_52X-bXow" /></figure><p>Although you are browsing youtube.com, multiple other domains can actually set cookies with information about your activity. There are a couple of ways for youtube.com and let’s say, google.com to cooperate this way. For example YouTube can embed the iframe of Google on the website you are on. That way Google will be able to set cookies for itself in the response headers.</p><p>Those cookies won’t be different from any other cookies that Google sets. They are still only available for google.com, and they are still not available for YouTube domain. And they will be sent as all other cookies with a new request to google.com. The only thing is — you didn’t have to visit their website.</p><p>This behaviour is mostly used for tracking user activity. If you see an advertisement on one site with some customised content related to another website search or activity, it’s probably because of cookies. That‘s why some browsers are disabling them by default. If you haven’t done it yet, I recommend it. You will probably have the same website functionality with much more anonymity.</p><p>That’s all about the basics and scope of cookies. In the second part, I will describe the rest of the flags and hopefully give you a better understanding of how you can easily increase your cookies security.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27fd40256793" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docplanner-tech/cookies-for-beginners-a-to-%C5%82-part-1-27fd40256793">Cookies for beginners: A to Ł(Part 1)</a> was originally published in <a href="https://medium.com/docplanner-tech">Docplanner Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>