{"id":13440406,"url":"https://github.com/EtherDream/jsproxy","last_synced_at":"2025-03-20T09:33:06.071Z","repository":{"id":37733350,"uuid":"173675448","full_name":"EtherDream/jsproxy","owner":"EtherDream","description":"An online proxy based on ServiceWorker","archived":false,"fork":false,"pushed_at":"2024-03-31T09:54:26.000Z","size":2889,"stargazers_count":9344,"open_issues_count":189,"forks_count":3594,"subscribers_count":214,"default_branch":"master","last_synced_at":"2025-03-19T21:26:38.879Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EtherDream.png","metadata":{"files":{"readme":"README.md","changelog":"changelogs/README.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-04T04:46:35.000Z","updated_at":"2025-03-19T14:25:43.000Z","dependencies_parsed_at":"2023-01-17T15:46:06.419Z","dependency_job_id":"b0be4c85-0580-419a-a7dc-c66f4bde5113","html_url":"https://github.com/EtherDream/jsproxy","commit_stats":{"total_commits":237,"total_committers":3,"mean_commits":79.0,"dds":0.008438818565400852,"last_synced_commit":"be161ed8bbaf987ec50a28204fe8f54ae3f2ad73"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EtherDream%2Fjsproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EtherDream%2Fjsproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EtherDream%2Fjsproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EtherDream%2Fjsproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EtherDream","download_url":"https://codeload.github.com/EtherDream/jsproxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244521683,"owners_count":20465887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:22.485Z","updated_at":"2025-03-20T09:33:06.031Z","avatar_url":"https://github.com/EtherDream.png","language":"Shell","funding_links":[],"categories":["Shell","inbox","Shell (473)"],"sub_categories":[],"readme":"\n# 更新\n\n* 2019-07-24 [v0.1.0](https://github.com/EtherDream/jsproxy/blob/master/changelogs/v0.1.0.md) 发布，主要修复了缓存失效的问题。网络接口和之前版本不兼容，请及时更新服务端和 cfworker。\n\n* 2019-06-22 [cfworker 无服务器版](cf-worker) 发布，长期使用演示服务的请使用该版本。\n\n[查看更多](changelogs)\n\n\n# 安装\n\n```bash\ncurl https://raw.githubusercontent.com/EtherDream/jsproxy/0.1.0/i.sh | bash\n```\n\n* 自动安装目前只支持 Linux x64，并且需要 root 权限\n\n* 安装过程中 80 端口能被外网访问（申请 HTTPS 证书）\n\n无法满足上述条件，或想了解安装细节，可尝试[手动安装](docs/setup.md)。\n\n测试: `https://服务器IP.xip.io:8443`（具体参考脚本输出）\n\n\n### 自定义域名\n\n将域名 `example.com` 解析到服务器 IP，然后执行：\n\n```bash\ncurl https://raw.githubusercontent.com/EtherDream/jsproxy/master/i.sh | bash -s example.com\n```\n\n访问: `https://example.com:8443`\n\n\n### 自定义端口\n\n默认端口为 8443 (HTTPS) 和 8080 (HTTP) ，如需改成 443 和 80，推荐使用端口转发：\n\n```bash\niptables -A PREROUTING -t nat -p tcp --dport 443 -j REDIRECT --to-ports 8443\niptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 8080\n```\n\n同时修改 `www.conf` 中的 `:8443` 为 `:443`。\n\n\n### 使用 GitHub Pages 前端\n\n本项目支持前后端分离，前端部分（`www` 目录下的文件）可部署在第三方 Web 服务器上。\n\n例如演示站点的前端部署于 GitHub Pages 服务，从而可使用个性域名（*.github.io），还能减少一定的流量开销。\n\nFork 本项目，进入 `gh-pages` 分支（该分支内容和 `www` 目录相同），编辑 `conf.js` 文件：\n\n* 节点列表（`node_map` 字段，包括节点 id 和节点主机）\n\n* 默认节点（`node_default` 字段，指定节点 id）\n\n访问 `https://用户名.github.io/jsproxy` 预览。\n\n\n# 维护\n\n```sh\n# 切换到 jsproxy 用户\nsu - jsproxy\n\n# 重启服务\n./run.sh reload\n\n# 关闭服务（参数和 nginx -s 相同）\n./run.sh quit\n\n# 启动服务\n./run.sh\n\n# 查看代理日志\ntail server/nginx/logs/proxy.log\n```\n\n目前暂未实现开机自启动。\n\n\n# 禁止外链\n\n默认情况下，代理接口允许所有 `github.io` 子站点调用，这可能导致不必要的流量消耗。\n\n如果希望只给自己网站使用，可编辑 `allowed-sites.conf`。（重启服务生效）\n\n\n# 安全策略\n\n如果不希望代理访问内网（避免 SSRF 风险），可执行 `setup-ipset.sh`：\n\n```bash\n/home/jsproxy/server/setup-ipset.sh\n```\n\n\u003e 需要 root 权限，依赖 `ipset` 命令\n\n该脚本可禁止 `jsporxy` 用户访问保留 IP 段（针对 TCP）。nginx 之外的程序也生效，但不影响其他用户。\n\n\n# 相关文章\n\n* [基于 JS Hook 技术，打造最先进的在线代理](https://github.com/EtherDream/jsproxy/blob/master/docs/blogs/js-hook.md)\n\n\n# 项目特点\n\n相比传统在线代理，本项目具有以下特点：\n\n## 服务端开销低\n\n传统在线代理几乎都是在服务端替换 HTML/JS/CSS 等资源中的 URL。这不仅需要对内容做大量的分析和处理，还需对流量进行解压和再压缩，消耗大量 CPU 资源。并且由于逻辑较复杂，通常使用 Python/PHP 等编程语言自己实现。\n\n为降低服务端开销，本项目使用浏览器的一个黑科技 —— Service Worker。它能让 JS 拦截网页产生的请求，并能自定义返回内容，相当于在浏览器内部实现一个反向代理。这使得绝大部分的内容处理都可以在浏览器上完成，服务器只需纯粹的转发流量。\n\n因此本项目服务端直接使用 nginx，并且转发过程不修改内容（只修改 HTTP 头），避免了内容处理产生的巨大开销。同时得益于 nginx 丰富的功能，很多常用需求无需重新造轮子，通过简单配置即可实现。并且无论性能还是稳定性，都远高于自己实现。\n\n## API 虚拟化\n\n传统在线代理大多只针对静态 URL 的替换，忽视了动态 URL 以及和 URL 相关的网页 API。例如 a.com 反向代理 google.com，但页面中 JS 读取 `document.domain` 得到的仍是 a.com。这可能导致某些业务逻辑出现问题。\n\n为缓解这个问题，本代理在页面头部注入一个 JS，用以重写绝大部分和 URL 相关的 API，使得页面中的 JS 获取到的仍是原始 URL：\n\n![](https://raw.githubusercontent.com/EtherDream/jsproxy-localtest/temp/hook.png)\n\n对于有些无法重写的 API，例如 `location`，本代理会将代码中字面出现的 `location` 替换成 `__location`，从而将操作转移到自定义对象上。当然对于非字面的情况（例如 `this['lo' + 'cation']`），目前还无法处理。\n\n\n# 类似项目\n\n目前找到的都是传统后端替换 URL 的方案。当然后端替换也有不少优点，例如浏览器兼容性高，甚至低版本的 IE 都可以使用。\n\n## zmirror\n\nGitHub: https://github.com/aploium/zmirror\n\n## php-proxy\n\nGitHub: https://github.com/jenssegers/php-proxy\n\n\n# 项目意义\n\n本项目主要用于以下技术的研究：\n\n* 网站镜像 / 沙盒化\n\n* 钓鱼网站检测技术\n\n* 前端资源访问加速\n\n当然请勿将本项目用于非法用途，否则后果自负。\n\nDemo 页面文明使用，不要进行登陆等涉及隐私的操作。\n\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEtherDream%2Fjsproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEtherDream%2Fjsproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEtherDream%2Fjsproxy/lists"}