An open API service indexing awesome lists of open source software.

https://github.com/andreas-brunner/astro-mail-obfuscation

Protect email addresses, phone numbers and other sensitive data from bots scraping the source code of your Astro app.
https://github.com/andreas-brunner/astro-mail-obfuscation

astro astro-component astro-integration bot-protection email-obfuscation email-protection email-security encoding obfuscation security spam-protection utility utils withastro

Last synced: 7 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# Astro Mail Obfuscation

[![CodeFactor](https://www.codefactor.io/repository/github/andreas-brunner/astro-mail-obfuscation/badge)](https://www.codefactor.io/repository/github/andreas-brunner/astro-mail-obfuscation)

**Supported HTML tags:** `h1`-`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 ``.

> **Important:** Server-side rendering is currently not supported.

## Installation

Install (recommended via Astro CLI):

```bash
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 `"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:**

```html

info@...
0123...

...info@......


  • John Doe

  • Jane Doe


info@...

```

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

## 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.

## 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:

```js
// 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 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.

## Limitations

While the majority of basic bots cannot execute JavaScript, this integration provides an effective and practical level of protection against simpler, more common bots. Astro Mail Obfuscation is a client-side solution that is particularly ideal for use on static sites.