Get a Pentest and security assessment of your IT network.

Cyber Security

TOR & Same Origin Policy: A Security Guide

TL;DR

Yes, TOR can introduce complexities with the Same Origin Policy (SOP) due to its hidden services and how it handles network connections. While not a direct *violation* of SOP in standard browser contexts, it creates scenarios where cross-site scripting (XSS) attacks are easier to exploit than on the regular web. This guide explains why and what you can do about it.

Understanding the Problem

The Same Origin Policy is a critical cyber security mechanism that restricts how a document or script made from one origin can interact with resources from another origin. An ‘origin’ is defined by protocol (http/https), domain, and port. TOR changes things because of:

  • Hidden Services (.onion addresses): These don’t have traditional DNS records, making standard SOP checks less effective.
  • Circuits: Your connection goes through multiple relays, potentially changing the perceived origin from a website’s perspective.

This doesn’t mean TOR *breaks* SOP entirely, but it weakens its protections in certain situations.

Step-by-Step Solutions

  1. Understand Hidden Service Origins:
    Hidden services have a unique origin based on their service descriptor. However, standard browsers don’t always treat them consistently with SOP rules.
  2. Be Extra Careful with JavaScript:
    JavaScript running within a TOR browser session (especially when interacting with hidden services) is more vulnerable to XSS attacks. Always validate and sanitise user input thoroughly.
  3. Content Security Policy (CSP):
    Implement strong CSP headers on your web applications, even if they are hosted as hidden services. This helps control the resources a browser is allowed to load, mitigating some XSS risks.
    Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:;
  4. Avoid Mixed Content:
    Ensure all resources (images, scripts, stylesheets) are loaded over HTTPS. Mixing HTTP and HTTPS content can create vulnerabilities.

    Check your site with a tool like:

  5. Subresource Integrity (SRI):
    Use SRI tags to verify the integrity of external scripts and stylesheets. This prevents attackers from injecting malicious code through compromised CDNs.
    <script src="https://example.com/script.js" integrity="sha384-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" crossorigin="anonymous"></script>
  6. Disable Unnecessary JavaScript:
    If possible, disable JavaScript entirely or use a browser extension like NoScript to control which scripts are allowed to run. This significantly reduces the attack surface.
  7. Regular Security Audits:
    Conduct regular security audits of your web applications, specifically focusing on XSS vulnerabilities. Use automated scanning tools and manual penetration testing.
  8. Be Aware of Onion Service Directory Attacks:
    Hidden services are susceptible to attacks targeting the onion service directory. Keep your service descriptors secure and updated.

Important Considerations

  • TOR is not a silver bullet: It provides anonymity, but doesn’t automatically make your website immune to cyber security threats.
  • User Education: Educate users about the risks of XSS and phishing attacks, especially when using TOR.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation