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

Release #7315

Merged
merged 3 commits into from
Dec 15, 2023
Merged

Release #7315

Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .env.compose
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ DB_NAME=gauzy
DB_USER=postgres
DB_PASS=gauzy_password
DB_LOGGING=all
DB_POOL_SIZE=20
DB_POOL_SIZE=40
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

Expand All @@ -89,8 +89,9 @@ MAGIC_CODE_EXPIRATION_TIME=600
TEAM_JOIN_REQUEST_EXPIRATION_TIME=86400

# Rate Limiting
THROTTLE_ENABLED=true
THROTTLE_TTL=60
THROTTLE_LIMIT=300
THROTTLE_LIMIT=10000

# Twitter OAuth Configuration
TWITTER_CLIENT_ID=XXXXXXX
Expand Down
5 changes: 3 additions & 2 deletions .env.demo.compose
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ DB_NAME=gauzy
DB_USER=postgres
DB_PASS=gauzy_password
DB_LOGGING=all
DB_POOL_SIZE=20
DB_POOL_SIZE=40
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

Expand All @@ -90,8 +90,9 @@ MAGIC_CODE_EXPIRATION_TIME=600
TEAM_JOIN_REQUEST_EXPIRATION_TIME=86400

# Rate Limiting
THROTTLE_ENABLED=true
THROTTLE_TTL=60
THROTTLE_LIMIT=300
THROTTLE_LIMIT=10000

# Twitter OAuth Configuration
TWITTER_CLIENT_ID=XXXXXXX
Expand Down
5 changes: 3 additions & 2 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ DB_NAME=gauzy
DB_USER=postgres
DB_PASS=root
DB_LOGGING=all
DB_POOL_SIZE=20
DB_POOL_SIZE=40
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

Expand All @@ -88,8 +88,9 @@ MAGIC_CODE_EXPIRATION_TIME=600
TEAM_JOIN_REQUEST_EXPIRATION_TIME=86400

# Rate Limiting
THROTTLE_ENABLED=true
THROTTLE_TTL=60
THROTTLE_LIMIT=300
THROTTLE_LIMIT=10000

# Twitter OAuth Configuration
TWITTER_CLIENT_ID=XXXXXXX
Expand Down
5 changes: 3 additions & 2 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ DB_NAME=gauzy
DB_USER=postgres
DB_PASS=root
DB_LOGGING=all
DB_POOL_SIZE=20
DB_POOL_SIZE=40
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

Expand All @@ -88,8 +88,9 @@ MAGIC_CODE_EXPIRATION_TIME=600
TEAM_JOIN_REQUEST_EXPIRATION_TIME=86400

# Rate Limiting
THROTTLE_ENABLED=true
THROTTLE_TTL=60
THROTTLE_LIMIT=300
THROTTLE_LIMIT=10000

# Twitter OAuth Configuration
TWITTER_CLIENT_ID=
Expand Down
5 changes: 3 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DB_TYPE=better-sqlite3
# DB_USER=postgres
# DB_PASS=root
# DB_LOGGING=all
# DB_POOL_SIZE=20
# DB_POOL_SIZE=40
# DB_CONNECTION_TIMEOUT=1000
# DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

Expand All @@ -72,8 +72,9 @@ MAGIC_CODE_EXPIRATION_TIME=600
TEAM_JOIN_REQUEST_EXPIRATION_TIME=86400

# Rate Limiting
THROTTLE_ENABLED=true
THROTTLE_TTL=60
THROTTLE_LIMIT=300
THROTTLE_LIMIT=10000

# Twitter OAuth Configuration
TWITTER_CLIENT_ID=XXXXXXX
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/desktop-app-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

strategy:
matrix:
os: [windows-latest-l]
os: [windows-latest]

steps:
- name: Check out Git repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/desktop-app-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

strategy:
matrix:
os: [windows-latest-l]
os: [windows-latest]

steps:
- name: Check out Git repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/desktop-timer-app-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:

strategy:
matrix:
os: [windows-latest-l]
os: [windows-latest]

steps:
- name: Check out Git repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/desktop-timer-app-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:

strategy:
matrix:
os: [windows-latest-l]
os: [windows-latest]

steps:
- name: Check out Git repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

strategy:
matrix:
os: [windows-latest-l]
os: [windows-latest]

steps:
- name: Check out Git repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:

strategy:
matrix:
os: [windows-latest-l]
os: [windows-latest]

steps:
- name: Check out Git repository
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/plugin-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getDbConfig(): DataSourceOptions {
// See https://typeorm.io/data-source-options#common-data-source-options
extra: {
// based on https://node-postgres.com/api/pool max connection pool size
max: process.env.DB_POOL_SIZE || 20,
max: process.env.DB_POOL_SIZE || 40,
// connection timeout
connectionTimeoutMillis: process.env.DB_CONNECTION_TIMEOUT
? parseInt(process.env.DB_CONNECTION_TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ switch (dbType) {
// See https://typeorm.io/data-source-options#common-data-source-options
extra: {
// based on https://node-postgres.com/api/pool max connection pool size
max: process.env.DB_POOL_SIZE || 20,
max: process.env.DB_POOL_SIZE || 40,
// connection timeout
connectionTimeoutMillis: process.env.DB_CONNECTION_TIMEOUT
? parseInt(process.env.DB_CONNECTION_TIMEOUT)
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export const environment: IEnvironment = {
/**
* Throttler (Rate Limiting) Options
*/
THROTTLE_TTL: parseInt(process.env.THROTTLE_TTL) || 60, // 60ms
THROTTLE_LIMIT: parseInt(process.env.THROTTLE_LIMIT) || 3000,
THROTTLE_TTL: parseInt(process.env.THROTTLE_TTL) || 60, // now it's 60 seconds, but in future versions of Throttle going to be 60ms!
THROTTLE_LIMIT: parseInt(process.env.THROTTLE_LIMIT) || 10000,

/**
* Jitsu Server Configuration
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const environment: IEnvironment = {
* Throttler (Rate Limiting) Options
*/
THROTTLE_TTL: parseInt(process.env.THROTTLE_TTL) || 60, // now it's 60 seconds, but in future versions of Throttle going to be 60ms!
THROTTLE_LIMIT: parseInt(process.env.THROTTLE_LIMIT) || 3000,
THROTTLE_LIMIT: parseInt(process.env.THROTTLE_LIMIT) || 10000,
THROTTLE_ENABLED: process.env.THROTTLE_ENABLED == 'true',

/**
* Jitsu Server Configuration
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/environments/ienvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface IEnvironment {
/**
* Throttler (Rate Limiting) Options
*/
THROTTLE_ENABLED?: boolean;
THROTTLE_TTL?: number;
THROTTLE_LIMIT?: number;

Expand Down
63 changes: 38 additions & 25 deletions packages/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ if (environment.sentry && environment.sentry.dsn) {
// Probot Configuration
ProbotModule.forRoot({
isGlobal: true,
path: 'integration/github/webhook', // Webhook URL in GitHub will be: https://api.gauzy.co/api/integration/github/webhook
// Webhook URL in GitHub will be: https://api.gauzy.co/api/integration/github/webhook
path: 'integration/github/webhook',
config: {
/** Client Configuration */
clientId: github.clientId,
Expand Down Expand Up @@ -267,14 +268,18 @@ if (environment.sentry && environment.sentry.dsn) {
echoEvents: jitsu.echoEvents
}
}),
ThrottlerModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService): ThrottlerModuleOptions =>
({
ttl: config.get('THROTTLE_TTL'),
limit: config.get('THROTTLE_LIMIT')
} as ThrottlerModuleOptions)
}),
...(environment.THROTTLE_ENABLED
? [
ThrottlerModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService): ThrottlerModuleOptions =>
({
ttl: config.get('THROTTLE_TTL'),
limit: config.get('THROTTLE_LIMIT')
} as ThrottlerModuleOptions)
})
]
: []),
CoreModule,
AuthModule,
UserModule,
Expand Down Expand Up @@ -403,26 +408,34 @@ if (environment.sentry && environment.sentry.dsn) {
controllers: [AppController],
providers: [
AppService,
{
provide: APP_GUARD,
useClass: ThrottlerBehindProxyGuard
},
...(environment.THROTTLE_ENABLED
? [
{
provide: APP_GUARD,
useClass: ThrottlerBehindProxyGuard
}
]
: []),
{
provide: APP_INTERCEPTOR,
useClass: TransformInterceptor
},
{
provide: APP_INTERCEPTOR,
useFactory: () =>
new SentryInterceptor({
filters: [
{
type: HttpException,
filter: (exception: HttpException) => 500 > exception.getStatus() // Only report 500 errors
}
]
})
}
...(environment.sentry && environment.sentry.dsn
? [
{
provide: APP_INTERCEPTOR,
useFactory: () =>
new SentryInterceptor({
filters: [
{
type: HttpException,
filter: (exception: HttpException) => 500 > exception.getStatus() // Only report 500 errors
}
]
})
}
]
: [])
],
exports: []
})
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ export async function bootstrap(pluginConfig?: Partial<IPluginConfig>): Promise<
'Authorization, Language, Tenant-Id, Organization-Id, X-Requested-With, X-Auth-Token, X-HTTP-Method-Override, Content-Type, Content-Language, Accept, Accept-Language, Observe'
});

// TODO: enable csurf
// TODO: enable csurf is not good idea because it was depricated.
// Maybe review https://github.com/Psifi-Solutions/csrf-csrf as alternative?
// As explained on the csurf middleware page https://github.com/expressjs/csurf#csurf,
// the csurf module requires either a session middleware or cookie-parser to be initialized first.
// app.use(csurf());

// We use sessions for Passport Auth
app.use(
expressSession({
secret: env.EXPRESS_SESSION_SECRET,
resave: true,
resave: true, // we use this because Memory store does not support 'touch' method
saveUninitialized: true
// cookie: { secure: true } // TODO
})
);

Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/core/context/request-context.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import { Request, Response, NextFunction } from 'express';

import { RequestContext } from './request-context';

// There are few alternatives to 'cls-hooked', see:
// https://docs.nestjs.com/recipes/async-local-storage
// https://github.com/papooch/nestjs-cls

@Injectable()
export class RequestContextMiddleware implements NestMiddleware {
use(
req: Request,
res: Response,
next: NextFunction
) {
use(req: Request, res: Response, next: NextFunction) {
const requestContext = new RequestContext(req, res);
const session = cls.getNamespace(RequestContext.name) || cls.createNamespace(RequestContext.name);

// Note: this is "session" created by "cls-hooked" lib code,
// not related to express "session" storage at all!
// Also, session.run essentially creates unique context for each
// request so all data is isolated without any potential conflicts
// for concurrent requests
session.run(async () => {
session.set(RequestContext.name, requestContext);
next();
Expand Down
Loading