Skip to content

Commit fb031ad

Browse files
committed
Rate limiting; validate jwt audience in backend auth middleware
1 parent dd5a3da commit fb031ad

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

app/app.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { join } from 'path';
77
// @ts-expect-error 7016 api-problem lacks a defined interface; code still works fine
88
import Problem from 'api-problem';
99
import querystring from 'querystring';
10+
import { rateLimit } from 'express-rate-limit';
1011

1112
import { name as appName, version as appVersion } from './package.json';
1213
import { DEFAULTCORS } from './src/components/constants';
@@ -45,6 +46,14 @@ app.use(
4546
})
4647
);
4748

49+
// rate limiting applied to all routes.
50+
// Current limit: 1000 requests/minute
51+
const limiter = rateLimit({
52+
windowMs: 60 * 1000,
53+
max: 1000,
54+
});
55+
app.use(limiter);
56+
4857
// Skip if running tests
4958
if (process.env.NODE_ENV !== 'test') {
5059
app.use(httpLogger);

app/package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"config": "^3.3.11",
4141
"cors": "^2.8.5",
4242
"express": "^4.18.3",
43+
"express-rate-limit": "^7.2.0",
4344
"express-winston": "^4.2.0",
4445
"helmet": "^7.1.0",
4546
"joi": "^17.13.1",

app/src/middleware/authentication.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export const currentUser = async (req: Request, res: Response, next: NextFunctio
3838
if (config.has('server.oidc.authority') && config.has('server.oidc.publicKey')) {
3939
const publicKey: string = config.get('server.oidc.publicKey');
4040
const pemKey = publicKey.startsWith('-----BEGIN') ? publicKey : _spkiWrapper(publicKey);
41-
isValid = jwt.verify(bearerToken, pemKey, { issuer: config.get('server.oidc.authority') });
41+
isValid = jwt.verify(bearerToken, pemKey, {
42+
issuer: config.get('server.oidc.authority'),
43+
audience: config.get('frontend.oidc.clientId')
44+
});
4245
} else {
4346
throw new Error(
4447
'OIDC environment variables `SERVER_OIDC_AUTHORITY` and `SERVER_OIDC_PUBLICKEY` must be defined'

frontend/src/services/interceptors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import type { AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } fr
1212
*/
1313
export function appAxios(options: AxiosRequestConfig = {}): AxiosInstance {
1414

15-
console.log(new ConfigService().getConfig().apiPath);
16-
1715
const instance = axios.create({
1816
baseURL: '/' + new ConfigService().getConfig().apiPath,
1917
timeout: 10000,

0 commit comments

Comments
 (0)