XSS
XSS 란, 보안이 약한 웹 어플리케이션에 대한 웹 기반 공격
XSS 공격의 희생자는 어플리케이션이 아닌 user
XSS 공격에서 해로운 컨텐츠는 javascript를 활용하여 전달 됨
클라이언트가 서버에서 받은 것중 위험한 것 존재할 가능성(해커 등)
CSRF
CORS
교차 출처 리소스 공유(Cross-Origin Resource Sharing, CORS)는 추가 HTTP 헤더를 사용하여, 한 출처에서 실행 중인 웹 애플리케이션이 다른 출처의 선택한 자원에 접근할 수 있는 권한을 부여하도록 브라우저에 알려주는 체제입니다. 웹 애플리케이션은 리소스가 자신의 출처(도메인, 프로토콜, 포트)와 다를 때 교차 출처 HTTP 요청을 실행합니다.
처음 전송되는 리소스의 도메인과 다른 도메인으로부터 리소스가 요청될 경우 해당 리소스는 Cross-Origin HTTP요청에 의해 요청됨
MDN
preflight, 사전 전달
먼저 OPTIONS 메서드를 통해 다른 도메인의 리소스로 HTTP 요청을 보내 실제 요청이 전송하기에 안전한지 확인
OPTIONS /resources/post-here/ HTTP/1.1
Host: bar.other
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Connection: keep-alive
Origin: http://foo.example
Access-Control-Request-Method: POST
Access-Control-Request-Headers: X-PINGOTHER, Content-Type
HTTP/1.1 204 No Content
Date: Mon, 01 Dec 2008 01:15:39 GMT
Server: Apache/2
Access-Control-Allow-Origin: https://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
Access-Control-Max-Age: 86400
Vary: Accept-Encoding, Origin
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
preflight request가 완료되면 실제 요청을 전송합니다.
POST /resources/post-here/ HTTP/1.1
Host: bar.other
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:71.0) Gecko/20100101 Firefox/71.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Connection: keep-alive
X-PINGOTHER: pingpong
Content-Type: text/xml; charset=UTF-8
Referer: https://foo.example/examples/preflightInvocation.html
Content-Length: 55
Origin: https://foo.example
Pragma: no-cache
Cache-Control: no-cache
<person><name>Arun</name></person>
HTTP/1.1 200 OK
Date: Mon, 01 Dec 2008 01:15:40 GMT
Server: Apache/2
Access-Control-Allow-Origin: https://foo.example
Vary: Accept-Encoding, Origin
Content-Encoding: gzip
Content-Length: 235
Keep-Alive: timeout=2, max=99
Connection: Keep-Alive
Content-Type: text/plain
[Some GZIP'd payload]
node.js에서 파일을 읽거나 쓰기 위해 fs 모듈을 사용하듯이, HTTP 요청과 응답을 다루기 위해 http 모듈을 사용
response.on(event, listener)
: 지정한 event에 대한 listener를 추가
response.writeHead(statusCode[, statusMessage][, headers])
: 이 메소드는 http의 header를 설정하는 메소드이다. 첫번째인자 200이나 404 와 같이 상태를 보여주는 코드다. 두번째는 사람들이 readable한 statusMessage이고, 마지막은 the response headers이다.
readable이란
end(data,[,encoding])
: 엔드 메소드는 본문을 작성하는 메소드이다.
server.listen()
: (Starts the HTTP server listening for connections. This method is identical to server.listen() from net.Server.)
http 서버가 연결을 위해 필요한 메소드?
'end'
: end는 더이상 data가 없을때 발동된다.
'data'
: chunk란, data의 chunk(덩어리 또는 조각)이다. 이 청크는 Buffer가 될 수 있고 String이 될 수도 있다.
여기에 toString() 을 사용해야 우리가 알 수 있는 데이터로 변환 시킬 수 있다.
things what I've confused at :
배열 안 요소 스트링화 가능
let a = [1,2];
a.toString() // "1,2"
a=[a]
String(a) // "1,2"