@@ -61,7 +61,7 @@ import axios from 'axios'
6161import { Request , Response , NextFunction } from 'express'
6262import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
6363import { Credential } from '../../database/entities/Credential'
64- import { decryptCredentialData , encryptCredentialData } from '../../utils'
64+ import { decryptCredentialData , encryptCredentialData , getEncryptionKey } from '../../utils'
6565import { InternalFlowiseError } from '../../errors/internalFlowiseError'
6666import { StatusCodes } from 'http-status-codes'
6767import { generateSuccessPage , generateErrorPage } from './templates'
@@ -306,6 +306,15 @@ router.get('/callback', async (req: Request, res: Response) => {
306306// Refresh OAuth2 access token
307307router . 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 }
0 commit comments