@lobehub/chat 1.19.12 → 1.19.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.19.13](https://github.com/lobehub/lobe-chat/compare/v1.19.12...v1.19.13)
6
+
7
+ <sup>Released on **2024-09-20**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Try to implement better ssrf-protect.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Try to implement better ssrf-protect, closes [#4044](https://github.com/lobehub/lobe-chat/issues/4044) ([e960a23](https://github.com/lobehub/lobe-chat/commit/e960a23))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 1.19.12](https://github.com/lobehub/lobe-chat/compare/v1.19.11...v1.19.12)
6
31
 
7
32
  <sup>Released on **2024-09-20**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.19.12",
3
+ "version": "1.19.13",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -203,6 +203,7 @@
203
203
  "remark": "^14.0.3",
204
204
  "remark-gfm": "^3.0.1",
205
205
  "remark-html": "^15.0.2",
206
+ "request-filtering-agent": "^2.0.1",
206
207
  "resolve-accept-language": "^3.1.5",
207
208
  "rtl-detect": "^1.1.2",
208
209
  "semver": "^7.6.3",
@@ -0,0 +1,19 @@
1
+ import { NextResponse } from 'next/server';
2
+ import fetch from 'node-fetch';
3
+ import { useAgent as ssrfAgent } from 'request-filtering-agent';
4
+
5
+ /**
6
+ * just for a proxy
7
+ */
8
+ export const POST = async (req: Request) => {
9
+ const url = await req.text();
10
+
11
+ try {
12
+ const res = await fetch(url, { agent: ssrfAgent(url) });
13
+
14
+ return new Response(await res.arrayBuffer(), { headers: { ...res.headers } });
15
+ } catch (err) {
16
+ console.error(err); // DNS lookup 127.0.0.1(family:4, host:127.0.0.1.nip.io) is not allowed. Because, It is private IP address.
17
+ return NextResponse.json({ error: 'Not support internal host proxy' }, { status: 400 });
18
+ }
19
+ };
@@ -63,7 +63,7 @@ export const userRouter = router({
63
63
  const sessionCount = await sessionModel.count();
64
64
 
65
65
  return {
66
- canEnablePWAGuide: messageCount >= 2,
66
+ canEnablePWAGuide: messageCount >= 4,
67
67
  canEnableTrace: messageCount >= 4,
68
68
  // 有消息,或者创建过助手,则认为有 conversation
69
69
  hasConversation: messageCount > 0 || sessionCount > 1,
@@ -1,4 +1,4 @@
1
- // TODO: 未来路由需要迁移到 trpc or /webapi
1
+ // TODO: 未来所有核心路由需要迁移到 trpc,部分不需要迁移的则走 webapi
2
2
 
3
3
  /* eslint-disable sort-keys-fix/sort-keys-fix */
4
4
  import { transform } from 'lodash-es';
@@ -17,7 +17,7 @@ const mapWithBasePath = <T extends object>(apis: T): T => {
17
17
  };
18
18
 
19
19
  export const API_ENDPOINTS = mapWithBasePath({
20
- proxy: '/api/proxy',
20
+ proxy: '/webapi/proxy',
21
21
  oauth: '/api/auth',
22
22
 
23
23
  // agent markets
@@ -23,7 +23,7 @@ export class ClientService implements IUserService {
23
23
 
24
24
  return {
25
25
  avatar: user.avatar,
26
- canEnablePWAGuide: messageCount >= 2,
26
+ canEnablePWAGuide: messageCount >= 4,
27
27
  canEnableTrace: messageCount >= 4,
28
28
  hasConversation: messageCount > 0 || sessionCount > 0,
29
29
  isOnboard: true,
@@ -1,34 +0,0 @@
1
- import { isPrivate } from 'ip';
2
- import { NextResponse } from 'next/server';
3
- import dns from 'node:dns';
4
- import { promisify } from 'node:util';
5
-
6
- const lookupAsync = promisify(dns.lookup);
7
-
8
- export const runtime = 'nodejs';
9
-
10
- /**
11
- * just for a proxy
12
- */
13
- export const POST = async (req: Request) => {
14
- const url = new URL(await req.text());
15
- let address;
16
-
17
- try {
18
- const lookupResult = await lookupAsync(url.hostname);
19
- address = lookupResult.address;
20
- } catch (err) {
21
- console.error(`${url.hostname} DNS parser error:`, err);
22
-
23
- return NextResponse.json({ error: 'DNS parser error' }, { status: 504 });
24
- }
25
-
26
- const isInternalHost = isPrivate(address);
27
-
28
- if (isInternalHost)
29
- return NextResponse.json({ error: 'Not support internal host proxy' }, { status: 400 });
30
-
31
- const res = await fetch(url.toString());
32
-
33
- return new Response(res.body, { headers: res.headers });
34
- };