Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function setCsrfCookie(response: HttpResponse, csrfToken: string): void {
const cookieName = Config.get('settings.csrf.cookie.name', CSRF_DEFAULT_COOKIE_NAME);
const options: CookieOptions = {
domain: Config.get('settings.csrf.cookie.domain'),
httpOnly: false,
path: Config.get('settings.csrf.cookie.path', CSRF_DEFAULT_COOKIE_PATH),
sameSite: Config.get('settings.csrf.cookie.sameSite'),
secure: Config.get('settings.csrf.cookie.secure')
};
// Express does not support options.maxAge === undefined.
const maxAge = Config.get('settings.csrf.cookie.maxAge');
if (maxAge) {
options.maxAge = maxAge;
}
response.setCookie(cookieName, csrfToken, options);
}
export function setCsrfCookie(response: HttpResponse, csrfToken: string): void {
const cookieName = Config.get('settings.csrf.cookie.name', CSRF_DEFAULT_COOKIE_NAME);
const options: CookieOptions = {
domain: Config.get('settings.csrf.cookie.domain'),
httpOnly: false,
path: Config.get('settings.csrf.cookie.path', CSRF_DEFAULT_COOKIE_PATH),
sameSite: Config.get('settings.csrf.cookie.sameSite'),
secure: Config.get('settings.csrf.cookie.secure')
};
// Express does not support options.maxAge === undefined.
const maxAge = Config.get('settings.csrf.cookie.maxAge');
if (maxAge) {
options.maxAge = maxAge;
}
response.setCookie(cookieName, csrfToken, options);
}
it('from AWS Cognito.', async () => {
const clientId = Config.get('cognito.clientId');
const domain = Config.get('cognito.domain');
const refreshToken = Config.get('cognito.refreshToken');
let token: string;
const region = Config.get('cognito.region');
const userPoolId = Config.get('cognito.userPoolId');
if (refreshToken === undefined) {
console.log('COGNITO_REFRESH_TOKEN not defined. Skipping this test...');
return;
}
try {
const { body } = await superagent
.post(`https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`)
.send('grant_type=refresh_token')
.send(`client_id=${clientId}`)
.send(`refresh_token=${refreshToken}`);
it('from Auth0.', () => {
const domain = Config.get('auth0.domain');
const audience = Config.get('auth0.audience');
const token = Config.get('auth0.token');
if (token === undefined) {
console.log('AUTH0_TOKEN not defined. Skipping this test...');
return;
}
class AppController {
@Get('/api/users/me')
@JWTRequired({
secretOrPublicKey: getRSAPublicKeyFromJWKS({
cache: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${domain}/.well-known/jwks.json`,
it('from AWS Cognito.', async () => {
const clientId = Config.get('cognito.clientId');
const domain = Config.get('cognito.domain');
const refreshToken = Config.get('cognito.refreshToken');
let token: string;
const region = Config.get('cognito.region');
const userPoolId = Config.get('cognito.userPoolId');
if (refreshToken === undefined) {
console.log('COGNITO_REFRESH_TOKEN not defined. Skipping this test...');
return;
}
try {
const { body } = await superagent
.post(`https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`)
.send('grant_type=refresh_token')
.send(`client_id=${clientId}`)
.send(`refresh_token=${refreshToken}`);
token = body.id_token;
private async generateLoginResponse(user: User): Promise {
const payload = {
email: user.email,
id: user.id,
};
const secret = Config.get('settings.jwt.secretOrPublicKey');
const token = await new Promise((resolve, reject) => {
sign(payload, secret, { subject: user.id.toString() }, (err, value: string) => {
if (err) {
return reject(err);
}
resolve(value);
});
});
return new HttpResponseOK({
token
});
}
}
const builder = new Builder(nuxt);
await builder.build();
} else {
await nuxt.ready();
}
await createConnection();
const app = createApp(AppController, {
postMiddlewares: [
nuxt.render
]
});
const httpServer = http.createServer(app);
const port = Config.get('port', 3001);
httpServer.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
}
async function main() {
await createConnection();
const app = createApp(AppController);
const httpServer = http.createServer(app);
const port = Config.get('port', 3001);
httpServer.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
}
async function main() {
const uri = Config.get('mongodb.uri');
connect(uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true });
const app = createApp(AppController);
const httpServer = http.createServer(app);
const port = Config.get('port', 3001);
httpServer.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
}
export async function getCsrfToken(session?: Session): Promise {
if (!Config.get('settings.csrf.enabled', true)) {
return 'CSRF protection disabled';
}
if (session) {
const csrfToken = session.get('csrfToken');
if (!csrfToken) {
throw new Error('CSRF token is missing in the session.');
}
return csrfToken;
}
const secret = Config.get('settings.csrf.secret');
if (!secret) {
throw new Error(
'[CONFIG] You must provide a secret with the configuration key settings.csrf.secret.'
);