Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
astro-mail-obfuscation
Advanced tools
An Astro integration that obfuscates email addresses in the source code by encoding them. The email addresses are only decoded and displayed on the client side using JavaScript, which helps protect against basic email scraping bots.
An Astro integration that effectively obfuscates email addresses in the source code by hiding them during the static build using XOR obfuscation. The email addresses are only revealed on the client side through JavaScript.
The XOR obfuscation method is effective against basic bots that scour the internet for email addresses, as many of these bots do not execute JavaScript (often for efficiency reasons).
This integration allows Astro developers to automate the obfuscation of email addresses, and in its current version, it is stable and production-ready.
npx astro add astro-mail-obfuscation
Done!
npm install astro-mail-obfuscation
// astro.config.mjs
import mailObfuscation from "astro-mail-obfuscation";
export default defineConfig({
integrations: [mailObfuscation()],
});
Done!
By default, the integration does not automatically obfuscate email addresses. Email addresses you want to obfuscate must be marked with the attribute data-obfuscation="1"
.
// Within .astro files
<a href="mailto:mail1@..." data-obfuscation="1">mail1@...</a>
<a href="mailto:mail2@..." data-obfuscation="1">Contact us!</a>
The number 1
currently holds no special function, but it ensures that XOR is used as the default obfuscation method. The attribute is required for the obfuscation to work.
After running npm run build
and opening the website in the browser, you'll notice that the email addresses no longer appear in the source code. They are only visible if JavaScript is enabled.
Once installed, the integration works out-of-the-box, and no adjustments are required. However, there are two optional configuration options:
You can customize the text shown when JavaScript is disabled.
The XOR key is automatically generated by default. It can be manually set but this is not recommended.
// astro.config.mjs
export default defineConfig({
integrations: [
astroMailObfuscation({
fallbackText: "...", // Default: "Please enable JavaScript!"
// userKey: "A1B3C2..." (Optional, changes not recommended!)
}),
],
});
Here is a comparison of the source code with and without the integration:
<a href="mailto:mail@...">mail@...</a>
The email address is visible in the source code and easily accessible to bots.
<a data-obfuscation="1">
<noscript>Please enable JavaScript!</noscript>
<span data-...="5b09c..." data-...="12d9A..."></span>
</a>
The email address is no longer visible in the source code, making it difficult for bots to extract it.
This integration uses an XOR-based obfuscation technique during the build process. Email addresses marked with data-obfuscation="1"
are obfuscated both in the link and the HTML content. A client-side JavaScript script then decodes the content and restores it in the browser, with the decryption key stored as a meta tag in the HTML.
This integration is not intended to protect against targeted attacks. However, it provides an effective layer of protection against most email-harvesting bots that do not execute JavaScript.
FAQs
Protect email addresses, phone numbers and other sensitive data from bots scraping the source code of your Astro app.
The npm package astro-mail-obfuscation receives a total of 3 weekly downloads. As such, astro-mail-obfuscation popularity was classified as not popular.
We found that astro-mail-obfuscation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.