add optional authorize callback and update dependencies #30
+1,432
−854
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Authorization Callback Support for WebSocket Subscriptions
Summary
Added optional
authorizecallback to enable server-side authorization checks before allowing WebSocket subscriptions. This allows applications to enforce access control policies on subscription requests.Motivation
The WebSocket server previously accepted all subscription requests without authorization checks. Applications like Solid servers need to enforce ACL permissions before allowing clients to subscribe to resource updates.
Changes
Modified
lib/server.js:authorizeoption to constructor (line 18)authorize(iri, req, callback)before subscriptionerr <uri> forbiddenwhen authorization denies accessack <uri>when authorization allows subscriptionauthorizecallback provided, subscriptions proceed as beforeUsage
The authorize callback receives:
iri- Resource URI being subscribed toreq- HTTP upgrade request objectcallback(err, allowed)- Call with(null, true)to allow,(null, false)or(error)to denyTests
Added 3 authorization callback tests in
test/websockets.js:should receive ack when authorization allows subscriptionshould receive err when authorization denies subscriptionshould receive err when authorization callback returns errorTest Results: 8 passing (82ms) - All existing tests remain passing
Compatibility
authorizeoption works unchangedSecurity
err <uri> forbiddenmessage