Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): added helmet, rate limit in sequence when respective configs are present #101

Merged
merged 33 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
86de539
feat(core): added helmet in sequence when helmet config is present
sf-kansara Dec 10, 2020
a66eacc
fix(authentication-service): apply useCustomSequence in component
sf-kansara Dec 10, 2020
0977364
fix(in-mail-service): apply useCustomSequence in component
sf-kansara Dec 10, 2020
5adcaf6
feat(core): use redisAction when redis config binding is present
sf-kansara Dec 10, 2020
860d547
fix(sandbox-testing): bumped up dependencies
sf-kansara Dec 11, 2020
b643036
refactor(core): depdendency upgrade
sf-kansara Dec 16, 2020
6a70a39
style(core): lint fixes
sf-kansara Dec 16, 2020
19acbe1
style(core): fixed lint issues
sf-kansara Dec 16, 2020
ac37f77
refactor(audit-service): upgraded loopback dependencies
sf-kansara Dec 16, 2020
b1c6274
style(audit-service): lint fixes
sf-kansara Dec 16, 2020
876333c
refactor(authentication-service): upgraded loopback dependencies
sf-kansara Dec 16, 2020
470f3f1
style(authentication-service): lint fixes
sf-kansara Dec 16, 2020
9c0e8e2
refactor(notification-service): upgraded loopback dependencies
sf-kansara Dec 16, 2020
93b1019
style(notification-service): lint fixes
sf-kansara Dec 16, 2020
f40f8ab
refactor(sandbox-testing): upgraded dependencies in notification sandbox
sf-kansara Dec 16, 2020
a4df335
style(sandbox-testing): lint fixes
sf-kansara Dec 16, 2020
c53a573
refactor(sandbox-testing): upgraded dependency
sf-kansara Dec 16, 2020
4c4767d
refactor(in-mail-service): upgraded loopback dependencies
sf-kansara Dec 16, 2020
9b1117b
style(in-mail-service): lint fixes
sf-kansara Dec 16, 2020
1ea08d8
style(in-mail-service): lint fixes
sf-kansara Dec 16, 2020
a11481d
refactor(core): updated package-lock.json
sf-kansara Dec 16, 2020
61caca3
refactor(scheduler-service): updated package-lock.json
sf-kansara Dec 16, 2020
409a52c
style(scheduler-service): lint fixes
sf-kansara Dec 16, 2020
4807500
refactor(video-conferencing-service): updated package-lock.json
sf-kansara Dec 16, 2020
0ba4a83
refactor(video-conferencing-service): lint fixes
sf-kansara Dec 16, 2020
27c6427
refactor(notification-service): updated package-lock.json
sf-kansara Dec 16, 2020
a178934
refactor(in-mail-service): updated package-lock.json
sf-kansara Dec 16, 2020
cf28808
refactor(authentication-service): updated package-lock.json
sf-kansara Dec 16, 2020
5e89007
refactor(audit-service): updated package-lock.json
sf-kansara Dec 16, 2020
750906d
refactor(sandbox-testing): updated package-lock.json
sf-kansara Dec 16, 2020
fdbdabf
feat(core): added ratelimiter component
sf-kansara Dec 16, 2020
74f947b
refactor(sandbox-testing): lint fixes in auth multitenant
sf-kansara Dec 16, 2020
8465051
test(sandbox-testing): tested helmet and ratelimiter with secure sequ…
sf-kansara Dec 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
coverage/

.eslintrc.js
5,322 changes: 2,326 additions & 2,996 deletions packages/core/package-lock.json

Large diffs are not rendered by default.

39 changes: 20 additions & 19 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,41 @@
"!*/__tests__"
],
"dependencies": {
"@loopback/boot": "^2.3.1",
"@loopback/context": "^3.9.4",
"@loopback/core": "^2.7.0",
"@loopback/repository": "^2.5.1",
"@loopback/rest": "^5.0.1",
"@loopback/service-proxy": "^2.2.6",
"@loopback/boot": "^3.1.0",
"@loopback/context": "^3.13.0",
"@loopback/core": "^2.12.0",
"@loopback/openapi-v3": "^5.1.2",
"@loopback/repository": "^3.2.0",
"@loopback/rest": "^9.0.0",
"@loopback/service-proxy": "^3.0.3",
"i18n": "^0.10.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.19",
"lodash": "^4.17.20",
"logform": "^2.1.2",
"loopback-datasource-juggler": "^4.21.2",
"loopback4-authentication": "^4.0.1",
"loopback4-authorization": "3.1.1",
"loopback4-helmet": "^1.0.3",
"loopback4-ratelimiter": "^1.0.0",
"loopback4-soft-delete": "^2.0.0",
"loopback4-authentication": "^4.1.0",
"loopback4-authorization": "^3.2.0",
"loopback4-helmet": "^2.0.0",
"loopback4-ratelimiter": "^2.0.0",
"loopback4-soft-delete": "^3.1.0",
"moment": "^2.26.0",
"moment-timezone": "^0.5.31",
"tslib": "^1.10.0",
"tslib": "^2.0.0",
"winston": "^3.2.1"
},
"devDependencies": {
"@loopback/build": "^5.4.1",
"@loopback/eslint-config": "^7.0.1",
"@loopback/testlab": "^3.1.5",
"@loopback/build": "^6.2.6",
"@loopback/eslint-config": "^10.0.2",
"@loopback/testlab": "^3.2.8",
"@types/i18n": "^0.8.6",
"@types/jsonwebtoken": "^8.5.0",
"@types/lodash": "^4.14.153",
"@types/moment": "^2.13.0",
"@types/moment-timezone": "^0.5.13",
"@types/node": "^10.17.24",
"eslint": "^7.0.0",
"@types/node": "^10.17.44",
"eslint": "^7.12.1",
"source-map-support": "^0.5.19",
"typescript": "~3.9.3"
"typescript": "~4.0.5"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {LocaleKey} from './enums';
import {SFCoreBindings} from './keys';
import {LoggerExtensionComponent} from './components';
import {CoreConfig} from './types';
import {Loopback4HelmetComponent} from 'loopback4-helmet';
import {RateLimiterComponent} from 'loopback4-ratelimiter';

export class CoreComponent implements Component {
constructor(
Expand All @@ -23,9 +25,12 @@ export class CoreComponent implements Component {
// Mount logger component
this.application.component(LoggerExtensionComponent);

this.application.component(Loopback4HelmetComponent);
this.application.component(RateLimiterComponent);

// Configure locale provider

if (this.coreConfig && this.coreConfig.configObject) {
if (this.coreConfig?.configObject) {
configure({...this.coreConfig.configObject, register: this.localeObj});
} else {
configure({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/logger-extension/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export namespace LOGGER {
/**
* Enum to define the supported log levels
*/
/* eslint-disable-next-line @typescript-eslint/naming-convention */
export enum LOG_LEVEL {
DEBUG,
INFO,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants/file-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class FileExtensions {
/* eslint-disable-next-line @typescript-eslint/naming-convention */
static readonly Prohibited = [
'.0xe',
'.A6P',
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/enums/status-codes.enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable-next-line @typescript-eslint/naming-convention */
export const enum STATUS_CODE {
// sonarignore:start
OK = 200,
Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/secure-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class SecureSequence implements SequenceHandler {
protected rateLimitAction: RateLimitAction,
@inject(SFCoreBindings.i18n)
protected i18n: i18nAPI, // sonarignore:end
@inject(RateLimitSecurityBindings.CONFIG, {optional: true})
private readonly rateLimitConfig?: object,
@inject(HelmetSecurityBindings.CONFIG, {optional: true})
private readonly helmetConfig?: object,
) {}

async handle(context: RequestContext) {
Expand All @@ -87,8 +91,13 @@ export class SecureSequence implements SequenceHandler {
const route = this.findRoute(request);
const args = await this.parseParams(request, route);

await this.rateLimitAction(request, response);
await this.helmetAction(request, response);
if (this.rateLimitConfig) {
sf-kansara marked this conversation as resolved.
Show resolved Hide resolved
await this.rateLimitAction(request, response);
}

if (this.helmetConfig) {
await this.helmetAction(request, response);
}

const authUser: IAuthUserWithPermissions = await this.authenticateRequest(
request,
Expand Down Expand Up @@ -167,8 +176,7 @@ export class SecureSequence implements SequenceHandler {
) {
return JSON.parse(err.message).error as Error;
} else if (
err.message &&
err.message.message &&
err.message?.message &&
isJsonString(err.message.message) &&
JSON.parse(err.message.message).error
) {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/service-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ export class ServiceSequence implements SequenceHandler {
) {
return JSON.parse(err.message).error as Error;
} else if (
err.message &&
err.message.message &&
err.message?.message &&
isJsonString(err.message.message) &&
JSON.parse(err.message.message).error
) {
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ export const getDOBFromAge = (age: number): Date => {
};

export const rateLimitKeyGen = (req: Request) => {
return (
(req.headers &&
req.headers.authorization &&
req.headers.authorization.replace(/bearer /i, '')) ||
req.ip
);
return req.headers?.authorization?.replace(/bearer /i, '') ?? req.ip;
};

export const rateLimitKeyGenPublic = (req: Request) =>
Expand Down
5 changes: 4 additions & 1 deletion sandbox/auth-multitenant-example/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ KEYCLOAK_HOST=
KEYCLOAK_REALM=
KEYCLOAK_CLIENT_ID=
KEYCLOAK_CLIENT_SECRET=
KEYCLOAK_CALLBACK_URL=
KEYCLOAK_CALLBACK_URL=
RATE_LIMITER_WINDOW_MS=
RATE_LIMITER_MAX_REQS=
X_FRAME_OPTIONS=
2 changes: 2 additions & 0 deletions sandbox/auth-multitenant-example/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
coverage/

.eslintrc.js
Loading