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):
506
506
}
507
507
508
508
# Y provider microservice
509
- # Note: Be careful, this value is currently the same as in the collaboration service.
510
509
Y_PROVIDER_API_KEY = values .Value (
511
510
environ_name = "Y_PROVIDER_API_KEY" ,
512
511
environ_prefix = None ,
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ jest.mock('../src/env', () => {
14
14
PORT : port ,
15
15
COLLABORATION_SERVER_ORIGIN : origin ,
16
16
COLLABORATION_SERVER_SECRET : 'test-secret-api-key' ,
17
+ Y_PROVIDER_API_KEY : 'yprovider-api-key' ,
17
18
} ;
18
19
} ) ;
19
20
@@ -115,7 +116,7 @@ describe('Server Tests', () => {
115
116
const response = await request ( app as any )
116
117
. post ( '/api/convert-markdown' )
117
118
. set ( 'Origin' , origin )
118
- . set ( 'Authorization' , 'test-secret -api-key' ) ;
119
+ . set ( 'Authorization' , 'yprovider -api-key' ) ;
119
120
120
121
expect ( response . status ) . toBe ( 400 ) ;
121
122
expect ( response . body . error ) . toBe ( 'Invalid request: missing content' ) ;
@@ -125,7 +126,7 @@ describe('Server Tests', () => {
125
126
const response = await request ( app as any )
126
127
. post ( '/api/convert-markdown' )
127
128
. set ( 'Origin' , origin )
128
- . set ( 'Authorization' , 'test-secret -api-key' )
129
+ . set ( 'Authorization' , 'yprovider -api-key' )
129
130
. send ( {
130
131
content : '' ,
131
132
} ) ;
Original file line number Diff line number Diff line change @@ -4,5 +4,7 @@ export const COLLABORATION_SERVER_ORIGIN =
4
4
process . env . COLLABORATION_SERVER_ORIGIN || 'http://localhost:3000' ;
5
5
export const COLLABORATION_SERVER_SECRET =
6
6
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' ;
7
9
export const PORT = Number ( process . env . PORT || 4444 ) ;
8
10
export 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';
4
4
import {
5
5
COLLABORATION_SERVER_ORIGIN ,
6
6
COLLABORATION_SERVER_SECRET ,
7
+ Y_PROVIDER_API_KEY ,
7
8
} from '@/env' ;
8
9
9
10
import { logger } from './utils' ;
10
11
12
+ const VALID_API_KEYS = [ COLLABORATION_SERVER_SECRET , Y_PROVIDER_API_KEY ] ;
13
+
11
14
export const httpSecurity = (
12
15
req : Request ,
13
16
res : Response ,
@@ -27,7 +30,7 @@ export const httpSecurity = (
27
30
// Secret API Key check
28
31
// Note: Changing this header to Bearer token format will break backend compatibility with this microservice.
29
32
const apiKey = req . headers [ 'authorization' ] ;
30
- if ( apiKey !== COLLABORATION_SERVER_SECRET ) {
33
+ if ( ! apiKey || ! VALID_API_KEYS . includes ( apiKey ) ) {
31
34
res . status ( 403 ) . json ( { error : 'Forbidden: Invalid API Key' } ) ;
32
35
return ;
33
36
}
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ yProvider:
105
105
COLLABORATION_LOGGING: true
106
106
COLLABORATION_SERVER_ORIGIN: https://impress.127.0.0.1.nip.io
107
107
COLLABORATION_SERVER_SECRET: my-secret
108
+ Y_PROVIDER_API_KEY: my-secret
108
109
109
110
ingress:
110
111
enabled: true
You can’t perform that action at this time.
0 commit comments