귀하는 로그인되어 있지 않습니다. 이대로 편집하면 귀하의 IP 주소가 편집 기록에 남게 됩니다.스팸 방지 검사입니다. 이것을 입력하지 마세요!== 보안 고려사항 == === Origin 검증 === 서버는 Origin 헤더를 보고 어떤 웹사이트와 소켓통신을 할지 결정하기 때문에 Origin 헤더는 웹소켓 통신에 중요한 역할을 한다. 서버에서 Origin을 검증하는 예제: <syntaxhighlight lang="javascript"> const wss = new WebSocket.Server({ port: 8080, verifyClient: (info) => { const origin = info.origin; const allowedOrigins = ['https://example.com', 'https://app.example.com']; return allowedOrigins.includes(origin); } }); </syntaxhighlight> === 인증과 인가 === 웹소켓 연결에서의 사용자 인증: <syntaxhighlight lang="javascript"> const wss = new WebSocket.Server({ port: 8080, verifyClient: (info, callback) => { // 토큰 검증 const token = info.req.url.split('token=')[1]; if (isValidToken(token)) { callback(true); } else { callback(false, 401, 'Unauthorized'); } } }); </syntaxhighlight> === Rate Limiting === [[DoS]] 공격 방지를 위한 연결 수 제한: <syntaxhighlight lang="javascript"> const connections = new Map(); wss.on('connection', (ws, req) => { const ip = req.connection.remoteAddress; const connectionCount = connections.get(ip) || 0; if (connectionCount >= 10) { ws.close(1008, 'Too many connections'); return; } connections.set(ip, connectionCount + 1); ws.on('close', () => { connections.set(ip, connections.get(ip) - 1); }); }); </syntaxhighlight> === CSRF 방지 === 웹소켓은 [[SOP]](Same-Origin Policy)의 영향을 받지 않으므로 [[CSRF]] 공격에 취약할 수 있다. 적절한 토큰 검증이 필요하다. 편집 요약 가온 위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 가온 위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요. 또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요! 취소 편집 도움말 (새 창에서 열림)