2

クライアントがセッションCookieを取得する前に、/ login urlが要求されない限り、NodeJSが接続の試行に応答しないようにします。リクエスト時にソケットを閉じるために、次のリスナーを追加しました。

server.listeners("request").unshift (request, response)->
  if(request and request.url == "/login")
    # Set /login as the only entrance point to the server
    # A session cookie will be set here
  else
    # Authenticate based on the session cookie
    # if the session is invalid or doesn't exist abort the connection
    request.connection.destroy()

このソリューションは、私が望むことを実行するのに十分ですか、それともサーバーはクライアントとのネゴシエーションを試みたり、要求の前に応答したりしますか?同じポートでsocket.ioを介してhttpsとWebSocketを使用しています。

4

2 に答える 2

0

By the time a request has been made, the server has already been accepting data from the client. There is nothing you can do about this, but unless you are concerned about someone flooding you with data, then this isn't much of a problem.

What you have is sufficient for what you ask, but keep in mind that the security of your solution heavily depends on that session validation. In particular, it would be wise to prevent a session from being opened by a different IP address than the one it was originally started on.

于 2012-09-17T02:55:20.810 に答える
0

サーバーはどの接続に対しても ssl ハンドシェイクに応答することがわかりました。これは、私のソリューションでは不十分であることを意味します。私はそれを調べて、私が望むことを達成する方法について別の質問を作成するかもしれません.

于 2012-09-17T11:12:37.500 に答える