mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 09:16:03 +03:00
[GH-ISSUE #933] Support header manipulation and pre-request scripting while establishing websocket connection #331
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#331
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rvit34 on GitHub (Jun 11, 2020).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/933
Is your feature request related to a problem? Please describe.
It would be nice to have an ability to add custom headers (host, api-key, etc.) to pass auth check during establishing websocket connection. Also I need to sign my request, so some pre-request script would be useful as well. Currently your tool does not provide such abilities.
Describe the solution you'd like
The Solution is similar you already have for regular http requests.
@LeoMartinDev commented on GitHub (Oct 3, 2020):
I'll look into it
@liyasthomas commented on GitHub (Oct 3, 2020):
@LeoMartinDev great. Let me know if you need any help.
@LeoMartinDev commented on GitHub (Oct 3, 2020):
Thanks ! IMO we should split this into several PR to minimize diff.
I'm going to add the Headers section in a first PR
@LeoMartinDev commented on GitHub (Oct 4, 2020):
That's much bigger than what I thought. I had to make a reusable Parameters Headers component & corresponding entries in the store (new websocket state).
@LeoMartinDev commented on GitHub (Oct 4, 2020):
Hmm I don't know if this feature is really useful as Websocket API allows only one header :
Sec-WebSocket-Protocolhttps://stackoverflow.com/questions/39853185/custom-headers-for-websocket-js@liyasthomas commented on GitHub (Oct 6, 2020):
@rvit34 can you produce an example of making use of custom headers in WebSocket
@jreffitt commented on GitHub (Nov 5, 2020):
So what about the 'origin' header? Seems important for security and it looked like I could use this tool to test a socket connection. This doesn't work and without being able to set the headers in the test it will never work... I am able to use node's SocketIO library to do this and my web ui example works.
@liyasthomas commented on GitHub (Nov 5, 2020):
As per this:
And per this:
So basically the WebSocket protocol doesn’t handle authorization or authentication. Practically, this means that a WebSocket opened from a page behind auth doesn’t “automatically” receive any sort of auth. Thus many servers use
Originheader verification to avoid abusing WebSocket endpoints. I guess that makes sense, it protects users from bad js even though it doesn't protect servers from bad clients.So it's better not to implement this where there could be a chance to forge
originheader and thus invite chances for abusing WebSocket endpoints.As per this:
Also: https://github.com/hoppscotch/hoppscotch/issues/1331#issuecomment-728881676
@jugglingjsons commented on GitHub (Dec 1, 2020):
I would like to drop my 3 cents on that.
With modern cloud environments ( I am talking about AWS api gateway specifically here) there's exactly the kind of magic necessary happening to pass the headers in.
Besides Authorization is not the only thing the headers can be used for. Imho there should be a way to define custom headers on connection. The other requests don't really need it as it's more of the responsibility of the app to retain the connection context somehow, but connection definitely needs them.
Taking a look at other clients, especially terminal ones, like wscat for example, it's perfectly fine to use custom headers in connect - they treat it as http handshake.
whatwg/websockets#16 Here's another thread where this discussion is ablaze.
@tayler-king commented on GitHub (Feb 28, 2023):
I think pre-request scripts for WebSocket connections would still be a good idea. A few ideas on this:
In my particular instance, I have a WebSocket server that requires authentication to establish the connection. A refresh token is used to generate an authentication token which is passed to the WebSocket server during the upgrade request.
It would be nice to be able to fetch a new authentication token as appropriate - they're short lived and invalidate the refresh token used for generation, meaning it's quite inconvenient to manually generate new tokens each time.