Skip to content

Commit

Permalink
🐛 fix: try to implement better ssrf-protect (lobehub#4044)
Browse files Browse the repository at this point in the history
* 🐛 fix: try to implement better ssrf-protect

* 🐛 fix: fix error

* 💄 style: improve pwa
  • Loading branch information
arvinxx committed Sep 20, 2024
1 parent 4e3b71b commit e960a23
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 38 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"remark": "^14.0.3",
"remark-gfm": "^3.0.1",
"remark-html": "^15.0.2",
"request-filtering-agent": "^2.0.1",
"resolve-accept-language": "^3.1.5",
"rtl-detect": "^1.1.2",
"semver": "^7.6.3",
Expand Down
34 changes: 0 additions & 34 deletions src/app/api/proxy/route.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/app/webapi/proxy/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextResponse } from 'next/server';
import fetch from 'node-fetch';
import { useAgent as ssrfAgent } from 'request-filtering-agent';

/**
* just for a proxy
*/
export const POST = async (req: Request) => {
const url = await req.text();

try {
const res = await fetch(url, { agent: ssrfAgent(url) });

return new Response(await res.arrayBuffer(), { headers: { ...res.headers } });
} catch (err) {
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.
return NextResponse.json({ error: 'Not support internal host proxy' }, { status: 400 });
}
};
2 changes: 1 addition & 1 deletion src/server/routers/lambda/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const userRouter = router({
const sessionCount = await sessionModel.count();

return {
canEnablePWAGuide: messageCount >= 2,
canEnablePWAGuide: messageCount >= 4,
canEnableTrace: messageCount >= 4,
// 有消息,或者创建过助手,则认为有 conversation
hasConversation: messageCount > 0 || sessionCount > 1,
Expand Down
4 changes: 2 additions & 2 deletions src/services/_url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO: 未来路由需要迁移到 trpc or /webapi
// TODO: 未来所有核心路由需要迁移到 trpc,部分不需要迁移的则走 webapi

/* eslint-disable sort-keys-fix/sort-keys-fix */
import { transform } from 'lodash-es';
Expand All @@ -17,7 +17,7 @@ const mapWithBasePath = <T extends object>(apis: T): T => {
};

export const API_ENDPOINTS = mapWithBasePath({
proxy: '/api/proxy',
proxy: '/webapi/proxy',
oauth: '/api/auth',

// agent markets
Expand Down
2 changes: 1 addition & 1 deletion src/services/user/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ClientService implements IUserService {

return {
avatar: user.avatar,
canEnablePWAGuide: messageCount >= 2,
canEnablePWAGuide: messageCount >= 4,
canEnableTrace: messageCount >= 4,
hasConversation: messageCount > 0 || sessionCount > 0,
isOnboard: true,
Expand Down

0 comments on commit e960a23

Please sign in to comment.