Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

astro-mail-obfuscation

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astro-mail-obfuscation

Protect email addresses, phone numbers, and other sensitive data from bots scraping the source code of your Astro apps.

  • 2.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Astro Mail Obfuscation

Supported HTML tags: h1 to h6, p, span, a, label, ul, ol, li, strong, b, em, i.

This Astro integration effectively prevents spam bots from extracting email addresses, phone numbers or other sensitive data from the source code of your website. You can manually select one of three methods or activate random mode to increase variation and make it harder for bots to extract data. The integration has been designed with a focus on stability, reliability, performance and seamless support for <ViewTransitions />.

Note: Server-side rendering is currently not supported.

CodeFactor

Installation

Install (recommended via Astro CLI):

npx astro add astro-mail-obfuscation

Usage

Add the data-obfuscation attribute to any HTML tag containing sensitive content to obfuscate it during the build process. You can use the values 1, 2 or 3 to manually select the method for the respective tag.

Alternatively, you can use data-obfuscation="0" to specify that the integration automatically selects one of the three methods at random during the build, which increases variability and makes interpretation by simple bots even more difficult.

Examples:

<!-- Manually select obfuscation method: -->
<a href="mailto:info@..." data-obfuscation="1">info@...</a>
<a href="tel:0123..." data-obfuscation="2">0123...</a>
<p>...<span data-obfuscation="3">info@...</span>...</p>
<!-- Automatically select a random obfuscation method: -->
<ul data-obfuscation="0">
  <li>John Doe</li>
  <li>Jane Doe</li>
</ul>
<label data-obfuscation="0">info@...</label>
<!-- Additional content... -->

Info: HTML tags that do not contain the data-obfuscation attribute are not obfuscated. This can be useful in certain situations (e.g. GDPR).

Configuration

This integration works out of the box with no required setup.

Nevertheless, a few settings can be made to control the behavior of the integration:

// astro.config.mjs
import mailObfuscation from "astro-mail-obfuscation";
export default defineConfig({
  integrations: [
    mailObfuscation({
      fallbackText: "Please enable JavaScript", // Default: "[PROTECTED!]"
      // userKey: "...", // Automatically generated
      // userSalt: "...", // Automatically generated (must be 8 characters if set manually)
      // concurrencyLimit: number, // Max concurrent tasks, default: 5 (p-limit)
      // allowedTags: ["button", "..."] // Add unsupported HTML tags to the whitelist
    }),
  ],
});

The fallbackText is displayed if the user has deactivated JavaScript in the browser.

Whenever you run the build process, userKey and userSalt are automatically regenerated by default. If you still want to set static values within your Astro configuration, please note that the userSalt must be exactly 8 characters long. The length of the userKey, on the other hand, is not limited.

The userKey and userSalt are set as a meta tag on all pages during the build process to make them accessible to the client-side JavaScript.

Please change the concurrencyLimit with caution, as a value that is too high could affect stability.

By default, 17 HTML tags are already supported, but if you still need support for more tags, add them to the allowedTags array.

Recommendation: In most cases, only the fallbackText needs to be adjusted. The default settings are already optimized for stable use.

Methods

The integration provides three XOR-based methods for obfuscation:

  • Method "1": XOR with userKey, resulting in hexadecimal encoding.
  • Method "2": XOR with userKey, resulting in Base64 encoding (dynamically reversed).
  • Method "3": XOR with userKey and userSalt, resulting in Base62 encoding.

Each method uses XOR-based encoding with additional keys to vary how the content is represented, making it harder for simpler bots to detect patterns. For increased variability, data-obfuscation="0" enables automatic mode, which randomly selects a method during the build to further complicate bot interpretation.

Limitations

While the majority of basic bots cannot execute JavaScript, this integration provides a practical level of protection for simpler, common bots. Astro Mail Obfuscation is a client-side solution ideal for static sites.

Keywords

FAQs

Package last updated on 01 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc