Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/server/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type ClientConfig = {
type ConfigType = {
basePath: string;
isProduction: boolean;
secureCookie: boolean;
logJson: boolean;
playground: boolean;
logLevel: string;
Expand Down Expand Up @@ -186,6 +187,7 @@ export default (): ConfigType => {
accountConfigPath: process.env.ACCOUNT_CONFIG_PATH || '',
torProxy: process.env.TOR_PROXY_SERVER || '',
isProduction,
secureCookie: process.env.SECURE_COOKIE === 'true',
headers,
throttler,
sso,
Expand Down
11 changes: 10 additions & 1 deletion src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
app.use(helmet());
app.use(
helmet({
contentSecurityPolicy: {
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
'upgrade-insecure-requests': null,
},
},
})
);
app.setGlobalPrefix(process.env.BASE_PATH || '');

await app.listen(process.env.PORT || 3001, process.env.HOST);
Expand Down
8 changes: 4 additions & 4 deletions src/server/modules/api/amboss/amboss.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class AmbossResolver {
if (ambossAuth) return ambossAuth;

const jwt = await this.ambossService.getAmbossJWT(user.id);
const isProduction = this.configService.get('isProduction');
const secureCookie = this.configService.get('secureCookie');

res.setHeader(
'Set-Cookie',
Expand All @@ -86,7 +86,7 @@ export class AmbossResolver {
httpOnly: true,
sameSite: true,
path: '/',
secure: isProduction,
secure: secureCookie,
})
);

Expand Down Expand Up @@ -293,7 +293,7 @@ export class AmbossResolver {
@CurrentUser() user: UserId
) {
const jwt = await this.ambossService.getAmbossJWT(user.id);
const isProduction = this.configService.get('isProduction');
const secureCookie = this.configService.get('secureCookie');

res.setHeader(
'Set-Cookie',
Expand All @@ -302,7 +302,7 @@ export class AmbossResolver {
httpOnly: true,
sameSite: true,
path: '/',
secure: isProduction,
secure: secureCookie,
})
);

Expand Down
10 changes: 6 additions & 4 deletions src/server/modules/api/auth/auth.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class AuthResolver {
const dangerousNoSSOAuth = this.configService.get('sso.dangerousNoSSOAuth');
const cookiePath = this.configService.get('cookiePath');
const isProduction = this.configService.get('isProduction');
const secureCookie = this.configService.get('secureCookie');

const ssoAccount = this.accountsService.getAccount('sso');

Expand Down Expand Up @@ -213,7 +214,7 @@ export class AuthResolver {
httpOnly: true,
sameSite: true,
path: '/',
secure: isProduction,
secure: secureCookie,
})
);
return true;
Expand All @@ -240,6 +241,7 @@ export class AuthResolver {
}

const isProduction = this.configService.get('isProduction');
const secureCookie = this.configService.get('secureCookie');
const disable2FA = this.configService.get('disable2FA');

if (account.encrypted) {
Expand Down Expand Up @@ -309,15 +311,15 @@ export class AuthResolver {
httpOnly: true,
sameSite: true,
path: '/',
secure: isProduction,
secure: secureCookie,
})
);
return info?.['version'] || ''; // TODO: Remove unsafe casting when GetWalletInfo type is updated
}

@Mutation(() => Boolean)
async logout(@Context() { res }: ContextType) {
const isProduction = this.configService.get('isProduction');
const secureCookie = this.configService.get('secureCookie');
const cookies = [];

for (const cookieName in appConstants) {
Expand All @@ -330,7 +332,7 @@ export class AuthResolver {
httpOnly: true,
sameSite: true,
path: '/',
secure: isProduction,
secure: secureCookie,
})
);
}
Expand Down
Loading