豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit df3f910

Browse files
author
Chloe Byun
committed
bug: rm refresh endpoint and require auth
1 parent 3542a04 commit df3f910

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

packages/components/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,13 +1476,16 @@ export const refreshOAuth2Token = async (
14761476
// Import fetch dynamically to avoid issues
14771477
const fetch = (await import('node-fetch')).default
14781478

1479-
// Call the refresh API endpoint
1479+
// Call the refresh API endpoint.
1480+
// x-flowise-internal-key authenticates this server-side call;
1481+
// the endpoint rejects requests that omit or mismatch this header.
14801482
const refreshResponse = await fetch(
14811483
`${options.baseURL || 'http://localhost:3000'}/api/v1/oauth2-credential/refresh/${credentialId}`,
14821484
{
14831485
method: 'POST',
14841486
headers: {
1485-
'Content-Type': 'application/json'
1487+
'Content-Type': 'application/json',
1488+
'x-flowise-internal-key': process.env.FLOWISE_SECRETKEY_OVERWRITE || ''
14861489
}
14871490
}
14881491
)

packages/server/src/routes/oauth2/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import axios from 'axios'
6161
import { Request, Response, NextFunction } from 'express'
6262
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
6363
import { Credential } from '../../database/entities/Credential'
64-
import { decryptCredentialData, encryptCredentialData } from '../../utils'
64+
import { decryptCredentialData, encryptCredentialData, getEncryptionKey } from '../../utils'
6565
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
6666
import { StatusCodes } from 'http-status-codes'
6767
import { generateSuccessPage, generateErrorPage } from './templates'
@@ -306,6 +306,15 @@ router.get('/callback', async (req: Request, res: Response) => {
306306
// Refresh OAuth2 access token
307307
router.post('/refresh/:credentialId', async (req: Request, res: Response, next: NextFunction) => {
308308
try {
309+
// This endpoint is called internally by server-side components during chatflow execution.
310+
// Validate that the request carries the internal encryption key so it cannot be called
311+
// unauthenticated from the outside.
312+
const providedKey = req.headers['x-flowise-internal-key'] as string | undefined
313+
const encryptionKey = await getEncryptionKey()
314+
if (!providedKey || !encryptionKey || providedKey !== encryptionKey) {
315+
return res.status(401).json({ success: false, message: 'Unauthorized' })
316+
}
317+
309318
const { credentialId } = req.params
310319

311320
const appServer = getRunningExpressApp()
@@ -389,13 +398,12 @@ router.post('/refresh/:credentialId', async (req: Request, res: Response, next:
389398
updatedDate: new Date()
390399
})
391400

392-
// Return success response
401+
// Return success response — intentionally omit token values from the body
393402
res.json({
394403
success: true,
395404
message: 'OAuth2 token refreshed successfully',
396405
credentialId: credential.id,
397406
tokenInfo: {
398-
...tokenData,
399407
has_new_refresh_token: !!tokenData.refresh_token,
400408
expires_at: updatedCredentialData.expires_at
401409
}

packages/server/src/utils/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const WHITELIST_URLS = [
3838
'/api/v1/pricing',
3939
'/api/v1/user/test',
4040
'/api/v1/oauth2-credential/callback',
41-
'/api/v1/oauth2-credential/refresh',
4241
'/api/v1/mcp/',
4342
'/api/v1/text-to-speech/generate',
4443
'/api/v1/text-to-speech/abort',

0 commit comments

Comments
 (0)