GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add optional authorize callback and update dependencies by bourgeoa · Pull Request #30 · nodeSolidServer/node-solid-ws

Conversation

@bourgeoa

@bourgeoa bourgeoa commented Jan 12, 2026

Copy link
Copy Markdown
Member

Add Authorization Callback Support for WebSocket Subscriptions

Summary

Added optional authorize callback 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:

  • Added authorize option to constructor (line 18)
  • Integrated authorization check in message handler (lines 54-68)
  • Calls authorize(iri, req, callback) before subscription
  • Returns err <uri> forbidden when authorization denies access
  • Returns ack <uri> when authorization allows subscription
  • Backward compatible - if no authorize callback provided, subscriptions proceed as before

Usage

const SolidWs = require('solid-ws')

const pubsub = new SolidWs(server, {
  authorize: function(iri, req, callback) {
    // Custom authorization logic
    const allowed = checkPermissions(iri, req)
    callback(null, allowed)
  }
})

The authorize callback receives:

  • iri - Resource URI being subscribed to
  • req - HTTP upgrade request object
  • callback(err, allowed) - Call with (null, true) to allow, (null, false) or (error) to deny

Tests

Added 3 authorization callback tests in test/websockets.js:

  • ✅ should receive ack when authorization allows subscription
  • ✅ should receive err when authorization denies subscription
  • ✅ should receive err when authorization callback returns error

Test Results: 8 passing (82ms) - All existing tests remain passing

Compatibility

  • ✅ Fully backward compatible - authorization is optional
  • ✅ Existing code without authorize option works unchanged
  • ✅ No breaking changes to API
  • ✅ No new dependencies

Security

  • Authorization checks occur before subscription is established
  • Invalid subscriptions receive err <uri> forbidden message
  • Authorization errors handled gracefully
  • Request object available for authentication/authorization context

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bourgeoa added 3 commits January 12, 2026 11:54
@bourgeoa
add optional authorize callback and update dependencies
fd0687d
@bourgeoa
add workflow
9326a01
@bourgeoa
0.5.0
07e7cd0
@bourgeoa bourgeoa self-assigned this Jan 12, 2026
@bourgeoa
bourgeoa requested a review from CxRes January 12, 2026 11:25
@bourgeoa bourgeoa linked an issue Jan 12, 2026 that may be closed by this pull request
Add authorization callback for subscription requests #28
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@CxRes CxRes Awaiting requested review from CxRes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@bourgeoa bourgeoa

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add authorization callback for subscription requests

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@bourgeoa
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.