Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/routes/auth/callback/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export async function GET(event) {
const slackProfile = slackProfileResJSON['user'];

const profilePic = slackProfile['profile']['image_1024'];
const username = slackProfile['profile']['display_name'];
const username =
slackProfile['profile']['display_name'] !== ''
? slackProfile['profile']['display_name']
: slackProfile['profile']['real_name'];
Comment on lines +109 to +112
Copy link

Choose a reason for hiding this comment

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

Bug: The username can be null, undefined, or '' if both display_name and real_name are invalid from Slack API, violating the NOT NULL database constraint for user name.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The code attempts to assign a username based on slackProfile['profile']['display_name'] or slackProfile['profile']['real_name']. If display_name is an empty string ('') and real_name is undefined, null, or '' (as per Slack API documentation), the username variable will receive an invalid value. This invalid value is then used directly in database INSERT or UPDATE operations for the name field, which is defined as NOT NULL. This will cause a database constraint violation, leading to a 500 error during the authentication flow.

💡 Suggested Fix

Before using slackProfile['profile']['real_name'], validate it to ensure it's not undefined, null, or ''. Provide a default fallback value (e.g., 'Anonymous User') if both display_name and real_name are invalid to satisfy the NOT NULL database constraint.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/routes/auth/callback/+server.ts#L109-L112

Potential issue: The code attempts to assign a `username` based on
`slackProfile['profile']['display_name']` or `slackProfile['profile']['real_name']`. If
`display_name` is an empty string ('') and `real_name` is `undefined`, `null`, or '' (as
per Slack API documentation), the `username` variable will receive an invalid value.
This invalid value is then used directly in database `INSERT` or `UPDATE` operations for
the `name` field, which is defined as `NOT NULL`. This will cause a database constraint
violation, leading to a 500 error during the authentication flow.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5628196


if (env.BETA_CHANNEL_ID && env.BETA_CHANNEL_ID.length > 0) {
const channelMembersURL = new URL('https://slack.com/api/conversations.members');
Expand Down
Loading