Skip to content

Conversation

@FloDwld
Copy link
Contributor

@FloDwld FloDwld commented Nov 4, 2025

This pull request fixes several security issues exploitable by low-privileged and unauthenticated users by adding missing authorization checks:

  • IDP service: Restrict deleting and updating IDP providers to host users. Additionally, only disclose the client secret to host users.
  • User service: Prevent registrations when setting "Disallow user registration" is active.
  • Memo Attachment service: Restrict setting attachments to own memos.
  • Memo Relation service: Restrict setting memo relations to own memos.
  • Reaction service: Restrict deletion of reactions to own reactions.

@FloDwld FloDwld requested a review from boojack as a code owner November 4, 2025 08:13
@FloDwld
Copy link
Contributor Author

FloDwld commented Nov 4, 2025

I've added a commit to fix the failing tests

@boojack boojack requested a review from Copilot November 5, 2025 00:49
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 security and access control across multiple API endpoints by adding authentication checks, permission validations, and sensitive data redaction.

Key Changes:

  • Added user registration control based on workspace settings with superuser bypass
  • Implemented authentication and authorization checks for memo-related operations
  • Added client secret redaction for non-host users when retrieving identity providers

Reviewed Changes

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

Show a summary per file
File Description
server/router/api/v1/user_service.go Adds workspace setting check to control user registration with superuser override
server/router/api/v1/reaction_service.go Adds authentication and ownership validation for deleting memo reactions
server/router/api/v1/memo_relation_service.go Adds authentication and ownership validation for setting memo relations
server/router/api/v1/memo_attachment_service.go Adds authentication and ownership validation for setting memo attachments
server/router/api/v1/idp_service.go Adds authentication checks for update/delete operations and client secret redaction based on user role
server/router/api/v1/test/idp_service_test.go Updates tests to use authenticated contexts and validates client secret redaction behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@boojack
Copy link
Member

boojack commented Nov 6, 2025

@claude

@claude
Copy link

claude bot commented Nov 6, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

1 similar comment
@claude
Copy link

claude bot commented Nov 6, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@boojack boojack merged commit 769dcd0 into usememos:main Nov 6, 2025
2 checks passed
boojack pushed a commit that referenced this pull request Nov 6, 2025
This commit addresses all critical and high-priority recommendations from the security review:

**Critical Fixes:**
- Add nil checks before accessing memo properties in SetMemoAttachments and SetMemoRelations
  to prevent potential nil pointer dereference
- Fix information disclosure in DeleteMemoReaction by returning consistent errors
  (now returns permission denied instead of not found to avoid revealing reaction existence)

**Medium Priority Improvements:**
- Add GetReaction() method to store interface for better performance
  (single reaction lookup instead of list operation)
- Implement GetReaction() in all database drivers (SQLite, MySQL, PostgreSQL)
- Update DeleteMemoReaction to use the new GetReaction() method

**Test Coverage:**
- Add comprehensive test coverage for SetMemoAttachments authorization checks
- Add comprehensive test coverage for SetMemoRelations authorization checks
- Add comprehensive test coverage for DeleteMemoReaction authorization checks
- Add comprehensive test coverage for CreateUser registration enforcement

All tests follow the same patterns as existing IDP service tests and cover:
- Success cases for resource owners
- Success cases for superuser/host users
- Permission denied cases for non-owners
- Unauthenticated access attempts
- Not found scenarios

Related to PR #5217 security review recommendations.
boojack pushed a commit that referenced this pull request Nov 6, 2025
This commit addresses all critical and high-priority recommendations from the security review:

**Critical Fixes:**
- Add nil checks before accessing memo properties in SetMemoAttachments and SetMemoRelations
  to prevent potential nil pointer dereference
- Fix information disclosure in DeleteMemoReaction by returning consistent errors
  (now returns permission denied instead of not found to avoid revealing reaction existence)

**Medium Priority Improvements:**
- Add GetReaction() method to store interface for better performance
  (single reaction lookup instead of list operation)
- Implement GetReaction() in all database drivers (SQLite, MySQL, PostgreSQL)
- Update DeleteMemoReaction to use the new GetReaction() method

**Test Coverage:**
- Add comprehensive test coverage for SetMemoAttachments authorization checks
- Add comprehensive test coverage for SetMemoRelations authorization checks
- Add comprehensive test coverage for DeleteMemoReaction authorization checks
- Add comprehensive test coverage for CreateUser registration enforcement

All tests follow the same patterns as existing IDP service tests and cover:
- Success cases for resource owners
- Success cases for superuser/host users
- Permission denied cases for non-owners
- Unauthenticated access attempts
- Not found scenarios

Related to PR #5217 security review recommendations.
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.

2 participants