Skip to content

Conversation

@pablohashescobar
Copy link
Member

@pablohashescobar pablohashescobar commented Oct 23, 2025

Description

  • Added logging for various authentication events in the Adapter and its subclasses, including email validation, user existence checks, and password strength validation.
  • Implemented error handling for GitHub OAuth email retrieval, ensuring proper logging of unexpected responses and missing primary emails.
  • Updated logging configuration in local and production settings to include a dedicated logger for authentication events.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Test Scenarios

  • check all authentication views

References

WEB-5225

Summary by CodeRabbit

Release Notes

  • Chores
    • Enhanced authentication system observability and monitoring capabilities through improved event logging across credential and OAuth authentication flows.

…sages

- Added logging for various authentication events in the Adapter and its subclasses, including email validation, user existence checks, and password strength validation.
- Implemented error handling for GitHub OAuth email retrieval, ensuring proper logging of unexpected responses and missing primary emails.
- Updated logging configuration in local and production settings to include a dedicated logger for authentication events.
Copilot AI review requested due to automatic review settings October 23, 2025 11:00
@cursor
Copy link

cursor bot commented Oct 23, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on November 20.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@makeplane
Copy link

makeplane bot commented Oct 23, 2025

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

The changes introduce comprehensive logging throughout the authentication module across adapter and provider components, with new logger configuration entries added to both local and production settings. Logging is added to validation paths, exception handlers, and provider-specific events without altering core logic or public API signatures.

Changes

Cohort / File(s) Summary
Logger Configuration
apps/api/plane/settings/local.py, apps/api/plane/settings/production.py
Added new logger entry "plane.authentication" with INFO level, console handler, and propagate set to False in both environments.
Base Adapter Logging
apps/api/plane/authentication/adapter/base.py
Added logger initialization in Adapter.__init__; logs errors for missing email, warnings for invalid email in sanitize_email, insufficient password strength in validate_password, and disabled signup without invite in __check_signup.
OAuth Adapter Logging
apps/api/plane/authentication/adapter/oauth.py
Added warning logs in exception handlers when RequestException occurs during get_user_token and get_user_response calls, capturing request/response context.
Email Provider Logging
apps/api/plane/authentication/provider/credentials/email.py
Added warning logs in set_user_data for three scenarios: existing user with same email, non-existent user, and password validation failures, each capturing email context.
GitHub OAuth Provider Logging
apps/api/plane/authentication/provider/oauth/github.py
Added runtime validation with error logs for invalid email response format and missing primary email; added warning logs for RequestException during email retrieval and organization membership failures; added info log when email is found.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

The changes follow a consistent, repetitive pattern of adding logging statements and logger configuration. The scope is contained within the authentication module with no logic alterations or signature changes. Most edits are straightforward logging additions that require minimal reasoning per file.

Poem

🐰 Hop, hop—the logs now glow so bright,
Each auth path logged from left to right,
Errors whisper, warnings peek,
Debugging becomes less mystique!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "[WEB-5225]feat: enhance authentication logging with detailed error and info message" accurately describes the main change in the changeset. The PR adds comprehensive logging throughout the authentication system, including logging in the Adapter base class, OAuth providers, email provider, and updates to logging configuration in both local and production settings. The title is concise, specific, and clearly conveys that the primary purpose is to enhance authentication logging with detailed messages, which aligns perfectly with the actual changes made across all modified files.
Description Check ✅ Passed The pull request description follows the required template structure and includes all mandatory sections. The Description section provides specific bullet points about logging additions in Adapter, GitHub OAuth error handling, and logging configuration updates. The Type of Change section is completed (though marked as "Bug fix" when it appears to be more of a feature/improvement). The Test Scenarios section is present with "check all authentication views," and the References section includes a link to the related issue WEB-5225. The Screenshots and Media section is omitted, but this is acceptable as it's marked optional in the template and not applicable for logging changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-api-sentry-errors

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 and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances authentication logging by adding detailed error and informational messages throughout the authentication flow. The changes focus on improving observability and debugging capabilities by logging key authentication events such as email validation failures, user existence checks, password strength validation, and OAuth-related errors.

Key changes:

  • Added dedicated logger configuration for authentication events in both local and production settings
  • Implemented comprehensive logging in authentication adapters and providers to capture error conditions and important events
  • Enhanced GitHub OAuth email retrieval with proper error handling and validation

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
apps/api/plane/settings/production.py Added logger configuration for plane.authentication
apps/api/plane/settings/local.py Added logger configuration for plane.authentication
apps/api/plane/authentication/provider/oauth/github.py Added error handling and logging for GitHub OAuth email retrieval and organization validation
apps/api/plane/authentication/provider/credentials/email.py Added logging for user existence checks and authentication failures
apps/api/plane/authentication/adapter/oauth.py Added logging for OAuth token and user response retrieval errors
apps/api/plane/authentication/adapter/base.py Added logger initialization and logging for email validation, password strength checks, and signup validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +127 to +130
self.logger.warning("Error getting email from GitHub", extra={
"headers": headers,
"emails_response": emails_response,
})
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

The variable emails_response may not be defined in this exception handler if the error occurs during the request itself (before line 110 is executed). This will cause a NameError. Move the logging inside the conditions where emails_response is guaranteed to be defined, or handle the case where it doesn't exist.

Copilot uses AI. Check for mistakes.
def sanitize_email(self, email):
# Check if email is present
if not email:
self.logger.error(f"Email is not present: {email}")
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

Logging the value of email when it's not present (i.e., None or empty) provides no useful information. Consider changing the message to just 'Email is not present' without the variable interpolation.

Suggested change
self.logger.error(f"Email is not present: {email}")
self.logger.error("Email is not present")

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

fix this.

"""Validate password strength"""
results = zxcvbn(self.code)
if results["score"] < 3:
self.logger.warning(f"Password is not strong enough: {email}")
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

This log message includes the email parameter but references password strength validation. Never log password values. While this appears to only log the email, the message could be misleading. Consider changing to 'Password is not strong enough for user: {email}' to be more explicit about what's being logged.

Suggested change
self.logger.warning(f"Password is not strong enough: {email}")
self.logger.warning(f"Password is not strong enough for user: {email}")

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +78
self.logger.warning("Error getting user token", extra={
"data": data,
"headers": headers,
})
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

Logging request data and headers in OAuth flows may expose sensitive information such as client secrets, authorization codes, or access tokens. Sanitize or exclude sensitive fields before logging.

Copilot uses AI. Check for mistakes.
)

email = self.__get_email(headers=headers)
self.logger.info("Email found", extra={
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

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

[nitpick] Logging email addresses at INFO level in production may have privacy implications depending on your data handling policies. Consider whether this should be logged at DEBUG level or if PII should be redacted/hashed.

Suggested change
self.logger.info("Email found", extra={
self.logger.debug("Email found", extra={

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 13

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80bd1b6 and 599e815.

📒 Files selected for processing (6)
  • apps/api/plane/authentication/adapter/base.py (7 hunks)
  • apps/api/plane/authentication/adapter/oauth.py (2 hunks)
  • apps/api/plane/authentication/provider/credentials/email.py (3 hunks)
  • apps/api/plane/authentication/provider/oauth/github.py (2 hunks)
  • apps/api/plane/settings/local.py (1 hunks)
  • apps/api/plane/settings/production.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/api/plane/authentication/provider/oauth/github.py (2)
packages/logger/src/config.ts (1)
  • logger (14-14)
apps/api/plane/authentication/adapter/error.py (1)
  • AuthenticationException (70-85)
apps/api/plane/authentication/provider/credentials/email.py (1)
packages/logger/src/config.ts (1)
  • logger (14-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Lint API
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
apps/api/plane/settings/local.py (1)

79-83: LGTM! Logger configuration is correct.

The new plane.authentication logger is properly configured with INFO level and console handler, consistent with other loggers in the file.

apps/api/plane/settings/production.py (1)

89-93: LGTM! Production logger configuration is correct.

The plane.authentication logger configuration is consistent with the local settings and appropriate for production use.

apps/api/plane/authentication/adapter/base.py (1)

4-4: LGTM! Logger initialization is correct.

The logging module import and logger initialization using plane.authentication are properly implemented.

Also applies to: 33-33

apps/api/plane/authentication/provider/oauth/github.py (1)

153-156: Consider whether user_login qualifies as PII for your use case.

Depending on your organization's privacy policy, GitHub usernames (user_login) might be considered PII. If so, this should not be logged.

If user_login is considered PII in your context, apply this diff:

             if not self.is_user_in_organization(user_info_response.get("login")):
-                self.logger.warning("User is not in organization", extra={
-                    "organization_id": self.organization_id,
-                    "user_login": user_info_response.get("login"),
-                })
+                self.logger.warning("User is not in required organization", extra={
+                    "organization_id": self.organization_id,
+                })
                 raise AuthenticationException(

def sanitize_email(self, email):
# Check if email is present
if not email:
self.logger.error(f"Email is not present: {email}")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII) in error messages.

Logging email addresses directly can violate privacy regulations (GDPR/CCPA). Consider logging a hashed version or omitting the email entirely from logs.

Apply this diff to remove PII from logs:

         if not email:
-            self.logger.error(f"Email is not present: {email}")
+            self.logger.error("Email is not present")
             raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.error(f"Email is not present: {email}")
if not email:
self.logger.error("Email is not present")
raise AuthenticationException(
🤖 Prompt for AI Agents
In apps/api/plane/authentication/adapter/base.py around line 56, the logger
currently prints the raw email (PII) in the error message; replace that with a
non-identifying value by either omitting the email entirely (e.g., "Email is not
present") or log a deterministic hash of the email (e.g., compute SHA-256 and
log the hex digest) so the log cannot be used to reconstruct the address; ensure
any new hashing uses a standard library hash function and that the message keeps
useful context without exposing the raw email.

try:
validate_email(email)
except ValidationError:
self.logger.warning(f"Email is not valid: {email}")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII) in validation messages.

Email addresses are personally identifiable information (PII). Logging them can create compliance issues with GDPR/CCPA.

Apply this diff:

         except ValidationError:
-            self.logger.warning(f"Email is not valid: {email}")
+            self.logger.warning("Email validation failed")
             raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.warning(f"Email is not valid: {email}")
except ValidationError:
self.logger.warning("Email validation failed")
raise AuthenticationException(
🤖 Prompt for AI Agents
In apps/api/plane/authentication/adapter/base.py around line 70, the logger
currently includes the full email address which is PII; change the message to
avoid logging the email (either drop the address entirely or log a masked/hashed
identifier). Replace the f-string that emits the raw email with a generic
warning like "Email validation failed" or with a masked form that retains no
identifiable information, and ensure any tests or call sites expecting the old
message are updated accordingly.

"""Validate password strength"""
results = zxcvbn(self.code)
if results["score"] < 3:
self.logger.warning(f"Password is not strong enough: {email}")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII) during password validation.

Logging email addresses alongside password validation events can create privacy concerns and compliance risks.

Apply this diff:

         if results["score"] < 3:
-            self.logger.warning(f"Password is not strong enough: {email}")
+            self.logger.warning("Password strength insufficient")
             raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.warning(f"Password is not strong enough: {email}")
if results["score"] < 3:
self.logger.warning("Password strength insufficient")
raise AuthenticationException(
🤖 Prompt for AI Agents
In apps/api/plane/authentication/adapter/base.py around line 83, the warning
currently logs the user's email (PII) during password validation; remove the raw
email from the log and either omit the identifier entirely or replace it with a
non-PII token (e.g., a masked username, a user ID, or a one-way hash of the
email) so the warning reads generically (e.g., "Password is not strong enough
for user" or "Password is not strong enough for user id=<masked>"); update the
logger call accordingly and ensure any masking/hashing is deterministic and
irreversible to avoid exposing PII.


# Check if sign up is disabled and invite is present or not
if ENABLE_SIGNUP == "0" and not WorkspaceMemberInvite.objects.filter(email=email).exists():
self.logger.warning(f"Sign up is disabled and invite is not present: {email}")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII) in signup checks.

Email addresses should not be logged to maintain user privacy and comply with data protection regulations.

Apply this diff:

         if ENABLE_SIGNUP == "0" and not WorkspaceMemberInvite.objects.filter(email=email).exists():
-            self.logger.warning(f"Sign up is disabled and invite is not present: {email}")
+            self.logger.warning("Sign up disabled without valid invite")
             # Raise exception
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.warning(f"Sign up is disabled and invite is not present: {email}")
if ENABLE_SIGNUP == "0" and not WorkspaceMemberInvite.objects.filter(email=email).exists():
self.logger.warning("Sign up disabled without valid invite")
# Raise exception
🤖 Prompt for AI Agents
In apps/api/plane/authentication/adapter/base.py around line 101, the warning
currently logs the user's email (PII); remove the raw email from log output and
replace it with a non-identifying value. Change the message to not include the
email (e.g., "Sign up is disabled and invite is not present") or, if you need
traceability, log a deterministic non-PII fingerprint such as a hashed or masked
form of the email (compute a one-way hash or mask local-part) instead of the
cleartext address; ensure no plaintext email is ever passed to logger.

Comment on lines +75 to +78
self.logger.warning("Error getting user token", extra={
"data": data,
"headers": headers,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging authorization headers containing tokens.

The headers parameter may contain sensitive authorization tokens (e.g., Bearer tokens). Logging these creates a security risk as tokens could be exposed in log files or monitoring systems.

Consider sanitizing headers before logging:

         except requests.RequestException:
-            self.logger.warning("Error getting user token", extra={
-                "data": data,
-                "headers": headers,
-            })
+            sanitized_headers = {k: v for k, v in (headers or {}).items() if k.lower() not in ['authorization', 'cookie']}
+            self.logger.warning("Error getting user token", extra={
+                "data": data,
+                "headers": sanitized_headers,
+            })
             code = self.authentication_error_code()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.warning("Error getting user token", extra={
"data": data,
"headers": headers,
})
sanitized_headers = {k: v for k, v in (headers or {}).items() if k.lower() not in ['authorization', 'cookie']}
self.logger.warning("Error getting user token", extra={
"data": data,
"headers": sanitized_headers,
})
🤖 Prompt for AI Agents
In apps/api/plane/authentication/adapter/oauth.py around lines 75 to 78, the
code logs the full headers which can contain sensitive authorization tokens;
sanitize headers before logging by removing or masking the Authorization (and
other sensitive) header values, e.g., copy headers, delete or replace the
Authorization value with a fixed masked string or boolean flag indicating its
presence, and then log that sanitized copy (or only non-sensitive headers) along
with data instead of the raw headers.

Comment on lines +79 to +81
self.logger.warning("Authentication failed", extra={
"email": self.key,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII) during authentication failures.

Logging email addresses in authentication failure events can expose user information and violate privacy regulations.

Apply this diff:

             if not user.check_password(self.code):
-                self.logger.warning("Authentication failed", extra={
-                    "email": self.key,
-                })
+                self.logger.warning("Authentication failed - invalid credentials")
                 raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.warning("Authentication failed", extra={
"email": self.key,
})
self.logger.warning("Authentication failed - invalid credentials")
🤖 Prompt for AI Agents
In apps/api/plane/authentication/provider/credentials/email.py around lines 79
to 81, remove the plain email from the authentication failure log to avoid
logging PII; instead either omit the "email" field entirely or log a
non-reversible identifier such as a SHA-256 hex digest of the email (compute
hash server-side before logging) or a redacted version (e.g., keep only domain
or first char with mask) and replace the extra field with that value so the
logger no longer contains the raw email address.

Comment on lines +112 to +117
if not isinstance(emails_response, list):
self.logger.error(f"Unexpected response format from GitHub emails API: {emails_response}")
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_OAUTH_PROVIDER_ERROR"],
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging API response containing email addresses (PII).

The emails_response variable contains a list of email addresses, which are PII. Logging this data can violate privacy regulations.

Apply this diff:

             # Ensure the response is a list before iterating
             if not isinstance(emails_response, list):
-                self.logger.error(f"Unexpected response format from GitHub emails API: {emails_response}")
+                self.logger.error(f"Unexpected response format from GitHub emails API: expected list, got {type(emails_response).__name__}")
                 raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not isinstance(emails_response, list):
self.logger.error(f"Unexpected response format from GitHub emails API: {emails_response}")
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_OAUTH_PROVIDER_ERROR"],
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
)
if not isinstance(emails_response, list):
self.logger.error(f"Unexpected response format from GitHub emails API: expected list, got {type(emails_response).__name__}")
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_OAUTH_PROVIDER_ERROR"],
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
)
🤖 Prompt for AI Agents
In apps/api/plane/authentication/provider/oauth/github.py around lines 112 to
117, the code currently logs the full emails_response (PII) on error; remove the
direct logging of emails_response and instead log a non-PII message such as the
unexpected response type/structure or the number of items (if safe) without
including actual email values, then raise the same AuthenticationException;
ensure no PII is written to logs (use type(...) or len(...) or a simple static
message) and keep the existing error_code/error_message behavior.

Comment on lines +119 to +124
if not email:
self.logger.error(f"No primary email found for user: {emails_response}")
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_OAUTH_PROVIDER_ERROR"],
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII) from API response.

Logging emails_response exposes user email addresses in logs, creating privacy and compliance risks.

Apply this diff:

             email = next((email["email"] for email in emails_response if email["primary"]), None)
             if not email:
-                self.logger.error(f"No primary email found for user: {emails_response}")
+                self.logger.error("No primary email found in GitHub response")
                 raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not email:
self.logger.error(f"No primary email found for user: {emails_response}")
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_OAUTH_PROVIDER_ERROR"],
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
)
if not email:
self.logger.error("No primary email found in GitHub response")
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_OAUTH_PROVIDER_ERROR"],
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
)
🤖 Prompt for AI Agents
In apps/api/plane/authentication/provider/oauth/github.py around lines 119 to
124, the code logs the full emails_response which may contain user email
addresses (PII); remove the emails_response from the log and instead log only
non-PII context (e.g., a generic message, the number of emails returned, or the
GitHub user id if available), then raise the same AuthenticationException;
ensure no email values or raw response bodies are written to logs or error
messages.

Comment on lines +127 to +130
self.logger.warning("Error getting email from GitHub", extra={
"headers": headers,
"emails_response": emails_response,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix undefined variable reference and avoid logging sensitive data.

There are two critical issues here:

  1. emails_response may not be defined if the exception occurs before line 110, causing a runtime error.
  2. Logging headers exposes authorization tokens, and emails_response contains PII.

Apply this diff:

         except requests.RequestException:
-            self.logger.warning("Error getting email from GitHub", extra={
-                "headers": headers,
-                "emails_response": emails_response,
-            })
+            self.logger.warning("Error getting email from GitHub")
             raise AuthenticationException(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.warning("Error getting email from GitHub", extra={
"headers": headers,
"emails_response": emails_response,
})
self.logger.warning("Error getting email from GitHub")
🤖 Prompt for AI Agents
In apps/api/plane/authentication/provider/oauth/github.py around lines 127 to
130, fix the undefined variable and sensitive logging: ensure you only reference
emails_response if it exists (e.g., check for a local variable or use a safe
default like None or include it in the log only when set), and stop logging raw
headers (remove headers from extra) — instead log non-sensitive context such as
the request URL, HTTP status code, and the caught exception message/traceback;
also avoid logging full email data/PII by redacting or logging only a count or
masked identifier.

Comment on lines +163 to +165
self.logger.info("Email found", extra={
"email": email,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid logging email addresses (PII).

Logging the retrieved email address exposes PII. Consider using a generic success message instead.

Apply this diff:

         email = self.__get_email(headers=headers)
-        self.logger.info("Email found", extra={
-            "email": email,
-        })
+        self.logger.info("Email successfully retrieved from GitHub")
         super().set_user_data(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.logger.info("Email found", extra={
"email": email,
})
self.logger.info("Email successfully retrieved from GitHub")
🤖 Prompt for AI Agents
In apps/api/plane/authentication/provider/oauth/github.py around lines 163 to
165, the logger currently records the user's email (PII); remove the email from
the log payload and replace the message with a generic success message (e.g.,
"Email found for GitHub user") or, if diagnostic context is required, log a
non-PII token such as a masked or hashed identifier instead of the full email;
ensure extra no longer contains the "email" field.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants