Missing Authentication on GraphQL Subscriptions onConnect Handler#2
Open
kolega-ai-dev wants to merge 1 commit intomainfrom
Open
Missing Authentication on GraphQL Subscriptions onConnect Handler#2kolega-ai-dev wants to merge 1 commit intomainfrom
kolega-ai-dev wants to merge 1 commit intomainfrom
Conversation
The onConnect handler for GraphQL subscriptions was empty, allowing any client to establish a WebSocket connection and subscribe to loggingLiveTrail without authentication. Added JWT verification in onConnect using the same RS256 credentials and permission checks (manage:system) used elsewhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Vulnerability identified and fix provided by Kolega.dev
Missing Authentication on GraphQL Subscriptions onConnect Handler
Location
server/core/servers.js:127-129Description
The GraphQL subscriptions
onConnecthandler is empty and does not validate or authenticate connection parameters. This means any client can establish a subscription connection without credentials.The
onConnecthandler at line 127-129 inservers.jsis empty, meaning WebSocket connections for GraphQL subscriptions are established without any authentication. The@authdirective used elsewhere (e.g.,LoggingQueryrequiresmanage:system) only protects Query/Mutation resolvers via field resolution wrapping — it does NOT apply to Subscription resolvers. TheloggingLiveTrailsubscription inlogging.jsdirectly returnsWIKI.GQLEmitter.asyncIterator('livetrail')without any auth check. The schema atlogging.graphqlline 14 showsloggingLiveTrail: LoggerTrailLinehas no@authdirective.This means any client can:
/graphql-subscriptionsloggingLiveTrailThis is unauthenticated access to sensitive operational logs that may contain file paths, database errors, configuration details, and other sensitive information.
Fix Applied
Implemented JWT authentication in the
onConnecthandler to validate WebSocket connections. The handler extracts the JWT token fromconnectionParams.token(sent by the client) or falls back to thejwtcookie from the WebSocket upgrade request headers. It verifies the token using the same RS256 credentials (WIKI.config.certs.public, audience, issuer) used by the existing passport JWT strategy, and requires themanage:systempermission — consistent with howLoggingQueryandLoggingMutationare protected via@auth(requires: ["manage:system"]). Updated the client-side WebSocket link to pass the JWT token viaconnectionParams.Tests/Linters Ran
npx eslint --format codeframe server/core/servers.js client/client-app.js): Passed with no errorsnpx jest --passWithNoTests):server/test/helpers/page.test.jspassed (3/3 tests). Cypress spec failures are pre-existing (require browser environment)node -c server/core/servers.js): Passedjsonwebtoken(direct dependency) andcookie(transitive viacookie-parser) are available and workingContribution Notes
fix:,feat:)jsonwebtokenis already a direct dependency, andcookieis available as a transitive dependency ofcookie-parser