轻量级开源 reCaptcha 替代方案

altcha-org / **altcha ** Public

GDPR、WCAG 2.2 AA 和 EAA 合规,具有 PoW 机制和高级反垃圾邮件过滤器的自托管 CAPTCHA 替代方案。 altcha.org

License

MIT license 990 stars 37 forks

ALTCHA

ALTCHA 利用工作量证明机制 (proof-of-work mechanism) 来保护您的网站、API 和在线服务免受垃圾邮件和滥用。与传统解决方案不同,ALTCHA 是自托管的,不依赖于 cookies 或指纹识别,并确保完全的用户隐私。它完全符合 GDPRWCAG 2.2 AA-level 以及 European Accessibility Act

欲了解更多详情,请访问 ALTCHA

功能

示例

服务器集成

CMS

更多反垃圾邮件解决方案

使用方法

ALTCHA widget 以 "Web Component" 形式分发,并 支持所有现代浏览器

1. 安装 ALTCHA

npm install altcha

在主文件中导入 altcha

import 'altcha';

或将 <script> 标签插入您的网站:

<script async defer src="/altcha.js" type="module"></script>

CDN: https://cdn.jsdelivr.net/gh/altcha-org/altcha@main/dist/altcha.min.js

2. 在您的表单中使用 <altcha-widget> 标签

<form>
 <altcha-widget
  challengeurl="https://..."
 ></altcha-widget> 
</form>

请参阅下面的 configuration 或访问 网站集成文档

3. 将 ALTCHA 与您的服务器集成

请参阅 服务器文档 以了解更多详细信息。

包大小

ALTCHA 的默认包很轻量级,它将所有资源(包括 CSS 和 JavaScript Web Worker)合并到一个文件中。GZIP 压缩后,总大小仅为 17 kB,这使得 ALTCHA 的 widget 比 reCAPTCHA 小 94%。

| Distribution | Size (GZIPped) | | ------------- | ------------- | | ALTCHA (v1.x) | 17 kB | | hCaptcha | 48+ kB | | reCAPTCHA | 270+ kB |

内容安全策略 (CSP)

WebComponent 的默认分发包在一个文件中包含了样式和 worker。这可能会导致严格 CSP 规则出现问题。如果需要严格的 CSP 合规性,请考虑使用位于 /dist_external 目录中的脚本。有关更多详细信息,请参阅 documentation

Configuration

必需选项(至少需要一个):

附加选项:

与垃圾邮件过滤器相关的选项:

数据混淆选项:

开发/测试选项:

插件

版本 0.9.x 引入了可以通过导入单个 plugin 脚本来启用的 plugins

import 'altcha/obfuscation';
import 'altcha';

建议在主 altcha之前 导入 plugin,以确保在创建任何 widget 实例之前正确注册。

altcha 包中内置的可用 plugin:

要为 widget 的特定实例启用特定 plugin,请在 widget 标签中使用 plugins 属性。 列出要启用的 plugin 的名称,用逗号分隔,例如 plugins="analytics,obfuscation"。 仍然需要按照上述方式导入 plugin。 plugins 属性仅指定哪些 plugin 应为该实例处于活动状态,即使已导入其他 plugin。

Programmatic Configuration

要以编程方式配置 widget,请使用 configure() 方法:

document.querySelector('#altcha').configure({
 challenge: {
  algorithm: 'SHA-256',
  challenge: '...',
  salt: '...',
  signature: '...',
 },
 strings: {
  label: 'Verify',
 },
});

可用的配置选项:

export interface Configure {
 auto?: 'off' | 'onfocus' | 'onload' | 'onsubmit';
 challenge?: {
  algorithm: string;
  challenge: string;
  maxnumber?: number;
  salt: string;
  signature: string;
 };
 challengeurl?: string;
 customfetch?: string | ((url: string, init?: RequestInit) => Promise<Response>);
 debug?: boolean;
 delay?: number;
 expire?: number;
 floating?: 'auto' | 'top' | 'bottom';
 floatinganchor?: string;
 floatingoffset?: number;
 floatingpersist?: boolean | 'focus';
 hidefooter?: boolean;
 hidelogo?: boolean;
 maxnumber?: number;
 mockerror?: boolean;
 name?: string;
 obfuscated?: string;
 refetchonexpire?: boolean;
 spamfilter?: boolean | 'ipAddress' | SpamFilter;
 strings?: {
  error: string;
  expired: string;
  footer: string;
  label: string;
  verified: string;
  verifying: string;
  waitAlert: string;
 }
 test?: boolean | number | 'delay';
 verifyurl?: string;
 workers?: number;
 workerurl?: string;
}

自定义 fetch 函数

在从服务器请求 challenge 时,widget 不会发送 cookies(即,它不使用 credentials: 'include')。 要修改此行为或添加自定义请求标头,请使用 customfetch 配置选项。 此选项允许您定义自定义请求函数。

自定义函数必须返回一个 Response 对象。

发送 Cookies

要在请求中包含 cookies,请使用 credentials: 'include'

function altchaCustomFetch(url: string, init: RequestInit) {
 return fetch(url, {
  ...init,
  credentials: 'include', // Include cookies with the request
 });
}

有关可能的请求选项的更多详细信息,请参阅 Request 文档。

使用 customfetch

customfetch 选项可以接受:

用法示例

<altcha-widget
 challengeurl="https://example.com/challenge"
 customfetch="altchaCustomFetch"
></altcha-widget>

事件

enum State {
 ERROR = 'error',
 VERIFIED = 'verified',
 VERIFYING = 'verifying',
 UNVERIFIED = 'unverified',
 EXPIRED = 'expired',
};

使用事件:

document.querySelector('#altcha').addEventListener('statechange', (ev) => {
 // See enum State above
 console.log('state:', ev.detail.state);
});

重要说明:

编程配置和事件侦听器都必须在 ALTCHA 脚本加载后调用/附加,例如在 window.addEventListener('load', ...) 中。

垃圾邮件过滤器

widget 与 ALTCHA 的 反垃圾邮件解决方案 集成,以允许检查提交的表单数据是否存在潜在的垃圾邮件。

垃圾邮件过滤器 API 分析提交的数据中的各种信号,以确定它是否表现出垃圾邮件的特征。 这种非侵入式过滤有助于减少垃圾邮件提交,而不会让合法用户感到沮丧。

垃圾邮件过滤器配置

可以通过将 spamfilter 选项设置为 trueipAddress(仅验证 IP 地址和时区)来使用默认配置启用垃圾邮件过滤器,或者可以使用以下配置架构对其进行自定义:

interface SpamFilter {
 blockedCountries?: string[];
 classifier?: string;
 disableRules?: string[];
 email?: string | false;
 expectedCountries?: string[];
 expectedLanguages?: string[];
 fields?: string[] | false;
 ipAddress?: string | false;
 text?: string | string[];
 timeZone?: string | false;
}

SpamFilter 配置选项:

要将电子邮件字段包含到 fields 中(以便更轻松地进行服务器端验证),请使用 spamfilter.fields: string[] 选项配置输入名称列表。

从垃圾邮件检查中排除输入

默认情况下,将对父表单中的所有文本输入和 textarea 进行垃圾邮件检查。 要排除特定的输入,请添加 data-no-spamfilter 属性。 或者,使用 fields 配置选项显式列出选中的字段。

贡献

请参阅 Contributing Guide 并请遵循我们的 Code of Conduct

赞助

该项目由 BAUSW.com - Digital Construction Site Diary 赞助,通过实时文档提高建筑项目的透明度和信任度。

License

MIT

关于

GDPR、WCAG 2.2 AA 和 EAA 合规,具有 PoW 机制和高级反垃圾邮件过滤器的自托管 CAPTCHA 替代方案。 altcha.org

Topics

recaptcha captcha svelte wcag spam-prevention spam-protection antispam spam-filtering spam-detection ddos-mitigation proof-of-work captcha-alternative ddos-protection webcomponent hcaptcha spam-api

Resources

Readme

License

MIT license

Code of conduct

Code of conduct

Security policy

Security policy