Skip to content

refactor: replace console.log with logger.debug in OAuth2 server#41563

Open
Rajkaran-122 wants to merge 1 commit into
RocketChat:developfrom
Rajkaran-122:refactor/oauth2-logger
Open

refactor: replace console.log with logger.debug in OAuth2 server#41563
Rajkaran-122 wants to merge 1 commit into
RocketChat:developfrom
Rajkaran-122:refactor/oauth2-logger

Conversation

@Rajkaran-122

@Rajkaran-122 Rajkaran-122 commented Jul 25, 2026

Copy link
Copy Markdown

Summary

This PR replaces a console.log statement in the OAuth2 server with the project's logging utility (logger.debug) to follow the existing logging conventions and avoid writing sensitive runtime information directly to standard output.

What Changed

  • Replaced console.log with logger.debug
  • Kept the existing behavior while using the project's logging infrastructure
  • No functional changes

Why

Using the centralized logger provides consistent logging behavior and is more appropriate for production environments.

Testing

  • Verified the code compiles
  • Confirmed there are no functional behavior changes

Checklist

  • Follows the project's coding conventions
  • No breaking changes
  • No API changes

@Rajkaran-122
Rajkaran-122 requested a review from a team as a code owner July 25, 2026 06:03
@dionisio-bot

dionisio-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f19d9dc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

OAuth2 debug logging now uses Rocket.Chat’s Logger in model methods and request middleware. The model exports the logger instance while keeping Model internal; OAuth2 behavior and return values remain unchanged.

Changes

OAuth2 logging

Layer / File(s) Summary
Model logger integration
apps/meteor/server/oauth2-server/model.ts
Adds the shared logger, makes Model non-exported, and replaces model console.log calls with logger.debug.
Route logger wiring
apps/meteor/server/oauth2-server/oauth.ts
Imports the shared logger and replaces request and transformation middleware logging with logger.debug.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested labels: type: chore

Suggested reviewers: julio-rocketchat

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing OAuth2 server console logging with logger.debug.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/server/oauth2-server/model.ts`:
- Around line 43-45: Prevent credential and personal-data exposure in OAuth
logging: in apps/meteor/server/oauth2-server/model.ts at lines 43-45, 76-79,
101-104, 133-148, 174-189, 216-219, 259-262, and 278-281, remove or redact
access tokens, refresh tokens, authorization codes, clientSecret, and full user
objects, retaining only safe metadata; in
apps/meteor/server/oauth2-server/oauth.ts at lines 49-52, log only the request
path rather than the full URL or query string. Update the relevant
getAccessToken and adjacent OAuth model methods without changing their behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33010d9e-3b38-41e7-853f-46cc127fbdf1

📥 Commits

Reviewing files that changed from the base of the PR and between 6dc66fb and f19d9dc.

📒 Files selected for processing (2)
  • apps/meteor/server/oauth2-server/model.ts
  • apps/meteor/server/oauth2-server/oauth.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/oauth2-server/oauth.ts
  • apps/meteor/server/oauth2-server/model.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/oauth2-server/oauth.ts
  • apps/meteor/server/oauth2-server/model.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/oauth2-server/oauth.ts
  • apps/meteor/server/oauth2-server/model.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/server/oauth2-server/oauth.ts
  • apps/meteor/server/oauth2-server/model.ts
🔇 Additional comments (4)
apps/meteor/server/oauth2-server/model.ts (2)

1-21: 🗄️ Data Integrity & Integration

Verify the Model export removal.

Model was changed from exported to internal, which is an API change despite the PR objective stating that APIs are unchanged. Confirm that no tests or server modules import Model; otherwise retain the export or update all consumers.


30-41: LGTM!

apps/meteor/server/oauth2-server/oauth.ts (2)

1-9: LGTM!


72-76: LGTM!

Comment on lines 43 to +45
async getAccessToken(accessToken: string): Promise<Token | Falsey> {
if (this.debug === true) {
console.log('[OAuth2Server]', 'in getAccessToken (bearerToken:', accessToken, ')');
logger.debug('in getAccessToken (bearerToken:', accessToken, ')');

Copy link
Copy Markdown
Contributor

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 log clientSecret.
  • 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-L79
  • apps/meteor/server/oauth2-server/model.ts#L101-L104
  • apps/meteor/server/oauth2-server/model.ts#L133-L148
  • apps/meteor/server/oauth2-server/model.ts#L174-L189
  • apps/meteor/server/oauth2-server/model.ts#L216-L219
  • apps/meteor/server/oauth2-server/model.ts#L259-L262
  • apps/meteor/server/oauth2-server/model.ts#L278-L281
  • apps/meteor/server/oauth2-server/oauth.ts#L49-L52
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/server/oauth2-server/model.ts` around lines 43 - 45, Prevent
credential and personal-data exposure in OAuth logging: in
apps/meteor/server/oauth2-server/model.ts at lines 43-45, 76-79, 101-104,
133-148, 174-189, 216-219, 259-262, and 278-281, remove or redact access tokens,
refresh tokens, authorization codes, clientSecret, and full user objects,
retaining only safe metadata; in apps/meteor/server/oauth2-server/oauth.ts at
lines 49-52, log only the request path rather than the full URL or query string.
Update the relevant getAccessToken and adjacent OAuth model methods without
changing their behavior.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/server/oauth2-server/oauth.ts">

<violation number="1" location="apps/meteor/server/oauth2-server/oauth.ts:51">
P2: Logging `req.url` can expose OAuth credentials (authorization codes, tokens) that appear in query strings. Consider logging only `req.path` or stripping query parameters to avoid leaking sensitive values to centralized log storage.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Logging req.url can expose OAuth credentials (authorization codes, tokens) that appear in query strings. Consider logging only req.path or stripping query parameters to avoid leaking sensitive values to centralized log storage.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/server/oauth2-server/oauth.ts, line 51:

<comment>Logging `req.url` can expose OAuth credentials (authorization codes, tokens) that appear in query strings. Consider logging only `req.path` or stripping query parameters to avoid leaking sensitive values to centralized log storage.</comment>

<file context>
@@ -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);
 			}
 			return next();
</file context>
Suggested change
logger.debug(req.method, req.url);
logger.debug(req.method, req.path);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants