当使用
wss://
时,URL 本身是否也加密了呢?例如,假设你有一个简单的 Sinatra Web 应用程序,用于接受 Web Socket 连接:class App < Sinatra::Base
get "/ws/:api_key/room/:id" do |api_key, id|
user = User.find_by(api_key: api_key)
room = Room.find(id)
if RoomAuthenticator.new(room).authorized?(user)
request.websocket do |ws|
ws.onopen { publish(room, "#{user.name} connected.") }
end
else
401
end
end
end
然后从客户端/浏览器中,使用JavaScript:
new WebSocket("wss://" + window.location.host + "/ws/" + user.api_key + "/room/" + room.id);
用户API密钥在URL中是加密的吗?还是容易受到攻击?
wss://
URL传递api_key
是否是一种安全的方式来传输这些信息。似乎无法通过WebSockets使用查询参数(例如:?api_key=VALUE
)或标头(例如:x-api-key: VALUE
)。 - Michael van Rooijen