nestjs csrf

https://gitissue.com/repos/jiayisheji/blog pass csrf https://github.com/expressjs/csurf/issues/21 main.ts import { NestFactory } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; import { join } from 'path' import { AppModule } from './app.module'; import * as cookieSession from 'cookie-session'; import * as helmet from 'helmet'; import * as cookieParser from 'cookie-parser'; import * as csurf from 'csurf'; import * as rateLimit from 'express-rate-limit'; async function bootstrap() { const app = await NestFactory.create( AppModule, ); app.init() app.useStaticAssets(join(__dirname, '..', 'public')); app.setBaseViewsDir(join(__dirname, '..', 'views')); app.setViewEngine('pug'); app.set('trust proxy', 1); app.use(cookieSession({ name: 'session', keys: ['key1', 'key2'] })); //app.enableCors(); app.use(helmet()); app.use(cookieParser()); //app.use(csurf({ cookie: true })); //正常是這行,但有些API POST時需要略過csrf app.use(function (req, res, next) { var mw = csurf({ cookie: true }); // console.log(req.url) // check real get url if (req.url === '/testpostcsrf') return next(); //pass csrf check mw(req, res, next); }); app.use( rateLimit({ windowMs: 15 * 60 * 1000, // 15 minutes max: 100, // limit each IP to 100 requests per windowMs }), ); await app.listen(3000); } bootstrap(); layout.pug doctype html html head title= title meta(content= csrfToken, name='csrf-token') body block content login.pug extends layout block content h1 Please log in if error p. #{error} form(action="/login",method="POST") input(type="hidden",name="_csrf",value=csrfToken) input(type="hidden",name="challenge",value=challenge) table(style="") tr td input(type="email",id="email",name="email",placeholder="email@foobar.com") td. (Example: "foo@bar.com") tr td input(type="password",id="password",name="password") td. (Example: "foobar") input(type="checkbox",id="remember",name="remember",value="1") label(for="remember") Remember me br input(type="submit",id="accept",value="Log in")

2019-07-25 · 1 min · 206 words · Me

nest.js 让我们用Nestjs来重写一个CNode

https://gitissue.com/repos/jiayisheji/blog 這網站中的 让我们用Nestjs来重写一个CNode(上、中、下) 幫了大忙,減少大量的浪費時間 =========== html -> jade/pug http://html2jade.aaron-powell.com/ when you html meta want to become jade/pug layout.pug meta(content= csrfToken, name='csrf-token')

2019-07-25 · 1 min · 21 words · Me

nodejs expressjs

https://expressjs.com/en/advanced/best-practice-security.html

2019-07-23 · 1 min · word · Me

[轉]nodejs vs golang Web3 Performance comparison

https://docs.etherniti.org/architecture/benchmarks/performance_test/

2019-07-13 · 1 min · word · Me

[轉]Node 在正式環境運行的對應方式

https://adon988.logdown.com/posts/7831077-the-corresponding-way-of-node-operation-in-the-formal-environment 在這裡要探討關於 node 到底適不適合在正式環境運行,在一開場首先說明我"過去"對於這個問題的看法,答案是:不適合。

2019-07-13 · 1 min · 4 words · Me