-
Notifications
You must be signed in to change notification settings - Fork 13.7k
refactor: replace console.log with logger.debug in OAuth2 server #41563
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
Open
Rajkaran-122
wants to merge
1
commit into
RocketChat:develop
Choose a base branch
from
Rajkaran-122:refactor/oauth2-logger
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,11 +1,12 @@ | ||||||
|
|
||||||
| import OAuthServer, { OAuthError, UnauthorizedRequestError } from '@node-oauth/oauth2-server'; | ||||||
| import { OAuthApps, Users } from '@rocket.chat/models'; | ||||||
| import express from 'express'; | ||||||
| import type { Express, NextFunction, Request, Response } from 'express'; | ||||||
| import { Accounts } from 'meteor/accounts-base'; | ||||||
|
|
||||||
| import type { ModelConfig } from './model'; | ||||||
| import { Model } from './model'; | ||||||
| import { Model, logger } from './model'; | ||||||
|
|
||||||
| export class OAuth2Server { | ||||||
| public app: Express; | ||||||
|
|
@@ -47,7 +48,7 @@ export class OAuth2Server { | |||||
|
|
||||||
| const debugMiddleware = function (req: Request, _res: Response, next: NextFunction) { | ||||||
| if (config.debug === true) { | ||||||
| console.log('[OAuth2Server]', req.method, req.url); | ||||||
| logger.debug(req.method, req.url); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Logging Prompt for AI agents
Suggested change
|
||||||
| } | ||||||
| return next(); | ||||||
| }; | ||||||
|
|
@@ -71,7 +72,7 @@ export class OAuth2Server { | |||||
| const transformRequestsNotUsingFormUrlencodedType = function (req: Request, _res: Response, next: NextFunction) { | ||||||
| if (!req.is('application/x-www-form-urlencoded') && req.method === 'POST') { | ||||||
| if (config.debug === true) { | ||||||
| console.log('[OAuth2Server]', 'Transforming a request to form-urlencoded with the query going to the body.'); | ||||||
| logger.debug('Transforming a request to form-urlencoded with the query going to the body.'); | ||||||
| } | ||||||
| req.headers['content-type'] = 'application/x-www-form-urlencoded'; | ||||||
| req.body = Object.assign({}, req.body, req.query); | ||||||
|
|
||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Prevent OAuth secrets from reaching centralized logs.
The model logs tokens, authorization codes, client secrets, and user data, while the middleware logs query strings that may contain the same credentials. Redact sensitive fields and log only request paths or safe metadata.
apps/meteor/server/oauth2-server/model.ts#L43-L45: remove or redact the access token.apps/meteor/server/oauth2-server/model.ts#L76-L79: never logclientSecret.apps/meteor/server/oauth2-server/model.ts#L101-L104: remove or redact the authorization code.apps/meteor/server/oauth2-server/model.ts#L133-L148: avoid logging the full user object.apps/meteor/server/oauth2-server/model.ts#L174-L189: remove access and refresh token values.apps/meteor/server/oauth2-server/model.ts#L216-L219: remove or redact the refresh token.apps/meteor/server/oauth2-server/model.ts#L259-L262: remove or redact the access token.apps/meteor/server/oauth2-server/model.ts#L278-L281: remove or redact the authorization code.apps/meteor/server/oauth2-server/oauth.ts#L49-L52: log the path instead of the full URL/query string.📍 Affects 2 files
apps/meteor/server/oauth2-server/model.ts#L43-L45(this comment)apps/meteor/server/oauth2-server/model.ts#L76-L79apps/meteor/server/oauth2-server/model.ts#L101-L104apps/meteor/server/oauth2-server/model.ts#L133-L148apps/meteor/server/oauth2-server/model.ts#L174-L189apps/meteor/server/oauth2-server/model.ts#L216-L219apps/meteor/server/oauth2-server/model.ts#L259-L262apps/meteor/server/oauth2-server/model.ts#L278-L281apps/meteor/server/oauth2-server/oauth.ts#L49-L52🤖 Prompt for AI Agents