2022.9.11.일요일 TIL: Express 보안 구현, 쿠키 개념 공부

Dorito·2022년 9월 12일
0

공부 기록

목록 보기
23/71

하루 개요

Express 구현 끝까지 하기
자료구조 & 리트코드/프로그래머스 문제 1개 풀기
네트워크 (ip계층) 공부
알고리즘 1 문제 풀이

Express 구현

Express Secure

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

Security best practices for Express applications in production include:

  • Don’t use deprecated or vulnerable versions of Express
  • Use TLS
  • Use Helmet
  • Use cookies securely
  • Prevent brute-force attacks against authorization
  • Ensure your dependencies are secure -> nsp모듈 사용
  • Avoid other known vulnerabilities
  • Additional considerations

Express generator

yarn add express-generator -g 설치
express -h[-help] 사용법

express myapp gen 디렉터리 안에 myapp 디렉터리 생성,

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

views 디렉터리에 있는 .jade는 HTML 코드를 좀 더 적은 코드로 생성해주는 문법 !!!
https://www.tutorialsteacher.com/nodejs/jade-template-engine

그 외 static 파일을 생성하는 부분이나 필요한 라우터를 설정하는 부분, 404에러를 처리하는 부분, 기타 에러를 처리하는 코드 등이 기본으로 작성되어 있음.

Express Template Engine

HTMl을 직접 타이핑할 필요 없게 해주는 템플릿 엔진!
보통 템플릿 엔진으로Pug 많이 쓴다.

Make some cookies with Node.js

https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
https://www.w3schools.com/nodejs/nodejs_get_started.asp

cookies are small strings that contain key-value pairs of information sent from the webserver to the browser to get information about the user.
The browser will then save them locally. This way, subsequent requests can be made to the server to immediately update user content on the website depending on the previous requests that a user made to the server. A cookie is HTTP generated; thus, called an HTTP cookie.

Cookies are mainly used for three purposes:

Session management
Logins, shopping carts, game scores, or anything else the server should remember

Personalization
User preferences, themes, and other settings

Tracking
Recording and analyzing user behavior

var http = require("http");

http
  .createServer(function (req, res) {
    res.writeHead(200, {
      "Content-Type": "text/html",
      "Set-cookie": ["yummy_cookie = choco", "tasty-cookie = strawberry"],
    });
    res.end("Hello World! This is Coookie");
  })
  .listen(3000);

How to read imformation in cookies at browser

https://www.section.io/engineering-education/what-are-cookies-nodejs/

하루 마무리

  • 완료한 것 ❌ 🔺 ✅
    Express 구현 끝까지 하기 ✅
    자료구조 & 리트코드/프로그래머스 문제 1개 풀기 🔺
    네트워크 (ip계층) 공부 ❌
  • 내일 할 것
    Express 쿠키 보안 관련 파기
    자료구조 & 리트코드/프로그래머스 문제 1개 풀기
    네트워크 (ip계층) 공부

  • 하루 반성
    자극에 취약해서 유튜브 쇼츠 새벽 내내 봤고 생패 꼬일 뻔함

  • 피드백
    자극을 줄이는 룰을 만들었다.

0개의 댓글