File tree Expand file tree Collapse file tree 5 files changed +10
-4
lines changed
frontend/servers/y-provider Expand file tree Collapse file tree 5 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -506,7 +506,6 @@ class Base(Configuration):
506506 }
507507
508508 # Y provider microservice
509- # Note: Be careful, this value is currently the same as in the collaboration service.
510509 Y_PROVIDER_API_KEY = values .Value (
511510 environ_name = "Y_PROVIDER_API_KEY" ,
512511 environ_prefix = None ,
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ jest.mock('../src/env', () => {
1414 PORT : port ,
1515 COLLABORATION_SERVER_ORIGIN : origin ,
1616 COLLABORATION_SERVER_SECRET : 'test-secret-api-key' ,
17+ Y_PROVIDER_API_KEY : 'yprovider-api-key' ,
1718 } ;
1819} ) ;
1920
@@ -115,7 +116,7 @@ describe('Server Tests', () => {
115116 const response = await request ( app as any )
116117 . post ( '/api/convert-markdown' )
117118 . set ( 'Origin' , origin )
118- . set ( 'Authorization' , 'test-secret -api-key' ) ;
119+ . set ( 'Authorization' , 'yprovider -api-key' ) ;
119120
120121 expect ( response . status ) . toBe ( 400 ) ;
121122 expect ( response . body . error ) . toBe ( 'Invalid request: missing content' ) ;
@@ -125,7 +126,7 @@ describe('Server Tests', () => {
125126 const response = await request ( app as any )
126127 . post ( '/api/convert-markdown' )
127128 . set ( 'Origin' , origin )
128- . set ( 'Authorization' , 'test-secret -api-key' )
129+ . set ( 'Authorization' , 'yprovider -api-key' )
129130 . send ( {
130131 content : '' ,
131132 } ) ;
Original file line number Diff line number Diff line change @@ -4,5 +4,7 @@ export const COLLABORATION_SERVER_ORIGIN =
44 process . env . COLLABORATION_SERVER_ORIGIN || 'http://localhost:3000' ;
55export const COLLABORATION_SERVER_SECRET =
66 process . env . COLLABORATION_SERVER_SECRET || 'secret-api-key' ;
7+ export const Y_PROVIDER_API_KEY =
8+ process . env . Y_PROVIDER_API_KEY || 'yprovider-api-key' ;
79export const PORT = Number ( process . env . PORT || 4444 ) ;
810export const SENTRY_DSN = process . env . SENTRY_DSN || '' ;
Original file line number Diff line number Diff line change @@ -4,10 +4,13 @@ import * as ws from 'ws';
44import {
55 COLLABORATION_SERVER_ORIGIN ,
66 COLLABORATION_SERVER_SECRET ,
7+ Y_PROVIDER_API_KEY ,
78} from '@/env' ;
89
910import { logger } from './utils' ;
1011
12+ const VALID_API_KEYS = [ COLLABORATION_SERVER_SECRET , Y_PROVIDER_API_KEY ] ;
13+
1114export const httpSecurity = (
1215 req : Request ,
1316 res : Response ,
@@ -27,7 +30,7 @@ export const httpSecurity = (
2730 // Secret API Key check
2831 // Note: Changing this header to Bearer token format will break backend compatibility with this microservice.
2932 const apiKey = req . headers [ 'authorization' ] ;
30- if ( apiKey !== COLLABORATION_SERVER_SECRET ) {
33+ if ( ! apiKey || ! VALID_API_KEYS . includes ( apiKey ) ) {
3134 res . status ( 403 ) . json ( { error : 'Forbidden: Invalid API Key' } ) ;
3235 return ;
3336 }
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ yProvider:
105105 COLLABORATION_LOGGING: true
106106 COLLABORATION_SERVER_ORIGIN: https://impress.127.0.0.1.nip.io
107107 COLLABORATION_SERVER_SECRET: my-secret
108+ Y_PROVIDER_API_KEY: my-secret
108109
109110ingress:
110111 enabled: true
You can’t perform that action at this time.
0 commit comments