Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02aa897

Browse files
committed
chore: update links for csrf blog
1 parent 4a68b2f commit 02aa897

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

public/blogs/csrf-mitigation.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ tags:
1313
---
1414

1515
<C>
16-
If you don't rely on a framework to do the heavy lifting for you, or a third party library. As I always say that you have to [understand]() the subject before you abstract it. Here's how to do it manually, but first note that none of the techniques below will work if you're already [XSS]() vulnerable
16+
If you don't rely on a framework to do the heavy lifting for you, or a third party library. As I always say that you have to <L href='/blog/fundamentals'>understand</L> the subject before you abstract it. Here's how to do it manually, but first note that none of the techniques below will work if you're already vulnerable to <L href='https://owasp.org/www-community/attacks/xss/'>XSS.</L>
1717
</C>
1818
<H2>Where Did The Request Come From?</H2>
1919
<C>
2020
If you do not trust the request's origin, block it.
2121
</C>
2222
<H3>"Origin" Header</H3>
2323
<C>
24-
Since the `Origin` header is being added automatically by browsers as part of the [`CORS`]() mechanism, you can check and validate the header, to check if the request that is coming in, actually comes from you site, block it if it doesn't
24+
Since the <L href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin'>`Origin`</L> header is being added automatically by browsers as part of the <L href='https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS'>`CORS`</L> mechanism, you can check and validate the header, to check if the request that is coming in, actually comes from you site, block it if it doesn't
2525
</C>
2626
<Code
2727
code={`if r.Header.Get("Origin") != "https://my-actual-site.com" {
@@ -34,7 +34,7 @@ Since the `Origin` header is being added automatically by browsers as part of th
3434
<H3>"Sec-Fetc-" Headers</H3>
3535

3636
<C>
37-
Fetch Metadata headers, [introduced]() last year to provide additional context about the resource request. But all you have to know for now is you can use it to to check the origin
37+
Fetch Metadata headers, introduced last year to provide additional context about the resource request. But all you have to know for now is you can use it to to check the origin
3838
</C>
3939
<Code
4040
code={`if secFetchSite := r.Header.Get("Sec-Fetch-Site");
@@ -47,7 +47,7 @@ Fetch Metadata headers, [introduced]() last year to provide additional context a
4747
showLineNumbers={false}
4848
/>
4949
<C>
50-
Learn more about `Sec-Fetch` headers [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Mode) and [here](https://w3c.github.io/webappsec-fetch-metadata/#sec-fetch-site-header)
50+
Learn more about `Sec-Fetch` headers <L href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Mode'>here</L> and <L href='https://w3c.github.io/webappsec-fetch-metadata/#sec-fetch-site-header)'>here</L>
5151
</C>
5252
<C>
5353
You can use a combo of these two, just to make sure, if one doesn't exist is altered the other might be used. But solely relying on headers is not sufficient, headers could potentially be tampered with or omitted due to certain browser vulnerabilities, network configurations or proxies misconfigurations. So other techniques should be employed too, like
@@ -65,9 +65,9 @@ There are two main ways to implement anti-CSRF tokens:
6565
</C>
6666
<H3>Stateless Services</H3>
6767
<C>
68-
As in, user sessions can be managed without a database by storing session information as a [JWT]() or [JWE]() within a [cookie](). To defend against CSRF attacks in this setup, use the "Signed Double Submit Cookie Method.":
68+
As in, user sessions can be managed without a database by storing session information as a <L href='https://datatracker.ietf.org/doc/html/rfc7519'>JWT</L> or <L href='https://datatracker.ietf.org/doc/html/rfc7516'>JWE</L> within a <L href='#cookies'>cookie</L>. To defend against CSRF attacks in this setup, use the "Signed Double Submit Cookie Method.":
6969
</C><C>
70-
This method involves generating a unique and cryptographically secure random value, typically a UUID, when a user first authenticates. This UUID is then embedded within both the payload of the JWT/JWE and the CSRF token. To ensure the integrity and authenticity of the CSRF token, use an [HMAC](https://datatracker.ietf.org/doc/html/rfc2104.html), which you combine a secret key (used for signing/encrypting the JWT/JWE) with a hash function like [Blake3](https://github.com/BLAKE3-team/BLAKE3) or SHA256 (make sure it's not computationally intensive but secure enough) , to produce a fixed-size hash value representing the message's integrity. The HMAC message includes two parts: a new random value for collision avoidance and the shared UUID between the JWT/JWE and the CSRF token.
70+
This method involves generating a unique and cryptographically secure random value, typically a UUID, when a user first authenticates. This UUID is then embedded within both the payload of the JWT/JWE and the CSRF token. To ensure the integrity and authenticity of the CSRF token, use an <L href='https://datatracker.ietf.org/doc/html/rfc2104.html'>HMAC</L>, which you combine a secret key (used for signing/encrypting the JWT/JWE) with a hash function like <L href='https://github.com/BLAKE3-team/BLAKE3'>Blake3</L> or SHA256 (make sure it's not computationally intensive but secure enough) , to produce a fixed-size hash value representing the message's integrity. The HMAC message includes two parts: a new random value for collision avoidance and the shared UUID between the JWT/JWE and the CSRF token.
7171
</C><C>
7272
The idea might **Go** like this
7373
</C>
@@ -243,22 +243,22 @@ Here's an AJAX example
243243
showLineNumbers={false}
244244
/>
245245
<C>
246-
If you want to see a framework implementation of the synchronized pattern , check out [`Django`]()'s implementation with the CSRF mitigation middleware, you can read the source code [here]().
246+
If you want to see a framework implementation of the synchronized pattern , check out <L href='https://docs.djangoproject.com'>`Django`</L>'s implementation with the CSRF mitigation middleware, you can read the source code <L href='https://github.com/django/django/blob/main/django/middleware/csrf.py'>here.</L>
247247
</C>
248-
<H2>Cookies</H2>
248+
<H2 id='cookies'>Cookies</H2>
249249
<C>
250250
Avoid setting cookies with a specific domain to minimize security risks. When a cookie is domain-specific, all subdomains share that cookie, which can pose risks if you get hit with a <L href="https://developer.mozilla.org/en-US/docs/Web/Security/Subdomain_takeovers">subdomain takeover.</L>
251251
</C><C>
252252
For session cookies, ensure they are protected by:
253253
</C><C>
254254
- \- Using the `HttpOnly` attribute to prevent client-side scripts from accessing cookies, enhancing security against XSS attacks.
255-
- \- Setting the `SameSite` attribute to `Lax` or `Strict` to control cookie behavior in cross-site requests, more [below]().
255+
- \- Setting the `SameSite` attribute to `Lax` or `Strict` to control cookie behavior in cross-site requests, more <L href='#samesite'>below</L>.
256256
- \- Avoid specifying a domain (`Domain=None`) to prevent cookies from being sent in cross-origin requests.
257257
- \- Using the `Secure` attribute to ensure that cookies are only sent over HTTPS connections.
258258
</C><C>
259-
Also, for enhanced security measures, consider cookie prefixes like `__Host-` and `__Secure-`, read more [here]()
259+
Also, for enhanced security measures, consider cookie prefixes like `__Host-` and `__Secure-`, read more <L href='https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-cookie-prefixes-00'>here.</L>
260260
</C>
261-
<H3>About "SameSite" Cookies</H3>
261+
<H3 id="#samesite">About "SameSite" Cookies</H3>
262262
<C>
263263
Use the `SameSite` cookie attribute to set your users sessions (older browsers do not support this)
264264
</C>
@@ -276,7 +276,7 @@ Or
276276
showLineNumbers={false}
277277
/>
278278
<C>
279-
Read about [`Lax`]() and [`Strict`]() from the official [RFC](). Here's is basically what they do:
279+
Read about `Lax` and `Strict` from the official <L href='https://datatracker.ietf.org/doc/html/draft-west-first-party-cookies-07'>RFC</L>. Here's is basically what they do:
280280
</C>
281281
<C>
282282
**``Strict``:** This value prevents cookies from being sent in all cross-site browsing contexts, including regular links. For example: You're logged in your banking account, which means you have a session cookie. If this banking website employs the Strict ``SameSite`` value for its session cookies, and you click on a link to perform a banking transaction from an external website (like a forum or email) say https://scam-me-please.com , the banking website won't receive the session cookie due to the ``Strict`` setting. Consequently, the user won't be able to complete the transaction because the session information is not sent with the request.
@@ -288,9 +288,9 @@ Read about [`Lax`]() and [`Strict`]() from the official [RFC](). Here's is basic
288288
<H2>User Interaction-Based CSRF Defense</H2>
289289

290290
<C>
291-
Requiring users to authenticate using their password, biometric data, security questions, or [OTP]() is a highly effective security measure. However, it can significantly impact user experience, so it's typically used only for critical operations like changing passwords or conducting financial transactions. Avoid using CAPTCHA for this purpose, as it's primarily aimed at preventing automated bot attacks and doesn't provide the necessary level of security for these sensitive activities.
291+
Requiring users to authenticate using their password, biometric data, security questions, or <L href="https://en.wikipedia.org/wiki/One-time_password">OTP</L> is a highly effective security measure. However, it can significantly impact user experience, so it's typically used only for critical operations like changing passwords or conducting financial transactions. Avoid using CAPTCHA for this purpose, as it's primarily aimed at preventing automated bot attacks and doesn't provide the necessary level of security for these sensitive activities.
292292
</C>
293293
<H2>HTTP Methods</H2>
294294
<C>
295-
And oh yeah, did I mention that for any state changing request, DON'T USE [safe methods]().
295+
And oh yeah, did I mention that for any state changing request, DON'T USE <L href='https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.1'>safe methods.</L>
296296
</C>

0 commit comments

Comments
 (0)