Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ui.js #690

Merged
merged 1 commit into from
Apr 15, 2021
Merged

Update ui.js #690

merged 1 commit into from
Apr 15, 2021

Conversation

ebertech
Copy link
Contributor

@ebertech ebertech commented Mar 10, 2021

copy the meta field from the original message if it exists.

I'd like use be able to annotate messages as they come in and bind them to a "user" using a socket.io middleware. This way, I can do the lookup once on establishing the connection and do a socket.use() handler to add that field to each update-value that comes back from the UI.

Right now, each node gets to do its own munging of the received message and there's no way (that I can figure) to easily inject this info in the socket middleware. While I could, in theory, do the lookup later using the socketid, I'd have to maintain some table somewhere that maps socketids to users. That seems like a recipe for leaks, whereas this way it's just done in the closure in the handler which should get cleaned up when the socket is released.

copy the meta field from the original message if it exists
@ebertech
Copy link
Contributor Author

Here's an example of how I want to use it:

    ui: { 
      path: "ui" ,
      ioMiddleware: [
          (socket, next) => {
            if(socket.conn.request.headers.cookie) {
              const username = lookupTheUser(socket.conn.request.headers.cookie) // look up the user
              socket.use((packet, next) => {
                if(packet[0] == 'update-value') {
                    packet[1].meta = {username: username};                                
                }
                next();
              });              
            }
            next();
          }
        ]
    },

@ebertech
Copy link
Contributor Author

thoughts?

@dceejay
Copy link
Member

dceejay commented Apr 14, 2021

my concern is that although I can understand your intended use, I can see that it could be used as a means for sending anything to the front end and could be exploited for lots of other purposes (eg in a template). We deliberately don't send complete msg to the front end in order to stop leakage and to minimise traffic.

@ebertech
Copy link
Contributor Author

ebertech commented Apr 14, 2021

Hi, maybe I'm not following. This is only on the way in from the front-end, not on the way out...

Or are you saying, that while my usecase is ingress, it can be abused to do egress as well? I mean... if people want to be awful they could be... but isn't that on them? They'd have to actively go in and try to mess with it.

@dceejay
Copy link
Member

dceejay commented Apr 15, 2021

indeed - you are correct. must wake up before looking at code. Happy to merge.
Note the Dashboard is still not inherently multi-user - all running on the single thread that is the Node_RED node application so I don't think this should be considered a way to truly enable multi-user - though I can see it helps separate your concerns.

@dceejay dceejay merged commit 9dd5820 into node-red:master Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants