Module16
Module16
Mitigation
a) Use Anti-CSRF Tokens: Implement anti-CSRF tokens in web forms
and requests. These tokens are unique to each user session and
must be submitted with every form or request. The server
validates the token to ensure the request is legitimate.
b) Token Placement: Place anti-CSRF tokens in a location that is
not accessible to attackers. Commonly, these tokens are
embedded in hidden fields within HTML forms.
c) SameSite Cookie Attribute: Utilize the SameSite cookie
attribute to control when cookies are sent with cross-site
requests. Setting it to "Strict" ensures that cookies are only
sent in a first-party context, providing an additional layer
of protection.
d) HTTP Referer Header Check: checking the HTTP Referer header
can help verify that requests originate from the expected
source. However, note that this header can be manipulated, and
not all browsers consistently send it.
e) Custom Request Headers: Include custom request headers in AJAX
requests and ensure that the server verifies the presence and
correctness of these headers.
f) Double-Submit Cookies: Implement double-submit cookie patterns
where the anti-CSRF token is stored both in a cookie and as a
request parameter. The server compares the values to validate
the request.
g) Use Frameworks with Built-in CSRF Protection: Many web
development frameworks provide built-in mechanisms for CSRF
protection. Utilize these features and follow best practices
recommended by the framework.
h) Educate Developers: Train developers on secure coding
practices, emphasizing the importance of implementing anti-
CSRF measures in web applications.
i) Implement Referer Policy: Set the Referrer-Policy header to
control how much referrer information is included with
requests. This can help in reducing the risk of CSRF attacks.
j) Check for Same-Site Cookie Support: Regularly check and ensure
that web applications and third-party libraries used in the
application support the SameSite cookie attribute.
k) Use Content Security Policy (CSP): Implement Content Security
Policy headers to restrict the sources from which resources
can be loaded. This can mitigate the risk of loading malicious
scripts.
Cookie Stealing and Session Hijacking
Mitigation
Implementing security measures at the user and website/application
levels is necessary to mitigate the danger of cookie theft and
session hijacking. The following tactics can be used to lessen these
risks:
For Users:
Use HTTPS: Verify that HTTPS is being used by the websites you
visit. In order to increase the difficulty of attackers
intercepting and stealing your session cookies, HTTPS encrypts
the data transferred between your browser and the website.
Awareness of Public Wi-Fi: Use caution when connecting to
public Wi-Fi networks. Refrain from logging into crucial
accounts or gaining access to private information while using
unsafe networks.
Log Out: Whenever you're finished using an account, make sure
to log out, especially on shared or public computers. This
makes it more difficult for attackers to use stolen cookies
and helps invalidate the session.
Two-Factor Authentication (2FA): Enable two-factor
authentication (2FA) whenever it's feasible. An extra element,
such as a temporary code from your phone, would still be
required for access to your account even if an attacker were
to get to obtain your session cookie.
Frequent Cookie Clearing: Especially after using a public
computer, periodically delete the cookies from your browser.
By eliminating older session cookies, this lessens the
possible impact of cookie theft but won't stop it entirely.