Skip to content

fix: prevent unauthorized access to other users' apps in /apps/by-owner endpoint#5396

Merged
spaceluke merged 4 commits intoapolloconfig:masterfrom
RooobinYe:fix/apps-by-owner-authorization-5388
Jun 8, 2025
Merged

fix: prevent unauthorized access to other users' apps in /apps/by-owner endpoint#5396
spaceluke merged 4 commits intoapolloconfig:masterfrom
RooobinYe:fix/apps-by-owner-authorization-5388

Conversation

@RooobinYe
Copy link
Copy Markdown
Member

@RooobinYe RooobinYe commented Jun 2, 2025

What's the purpose of this PR

Enhance system security to prevent users from unauthorized access to other users' application information while maintaining API backward compatibility.

This PR is fully replicate the permission design of the favorites interface.

Which issue(s) this PR fixes:

Fixes #5388

Brief changelog

Security Fix:

  • Fixed unauthorized access vulnerability in /apps/by-owner endpoint
  • Added user validation to prevent querying other users' applications
  • Ensures users can only access their own app lists (similar to favorites endpoint)
  • Addresses security issue /apps/by-owner接口越权问题 #5388

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced security by restricting application access to only the authenticated user's own apps, preventing unauthorized access via the apps-by-owner endpoint.
  • Documentation

    • Added release notes detailing the security improvement.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 2, 2025

"""

Walkthrough

The changes restrict the /apps/by-owner endpoint to only allow users to query their own applications. The controller now retrieves the logged-in user's identity internally and removes the ability to specify an arbitrary owner parameter. Corresponding frontend service and controller calls were updated to use the new endpoint /apps/by-self. A security note was added to the release notes.

Changes

File(s) Change Summary
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java Renamed and refactored findAppsByOwner to findAppsBySelf to use logged-in user info internally, removing owner parameter.
apollo-portal/src/main/resources/static/scripts/controller/IndexController.js Updated getUserCreatedApps to call AppService.find_app_by_self without owner parameter.
apollo-portal/src/main/resources/static/scripts/services/AppService.js Renamed resource and service method from find_app_by_owner to find_app_by_self, changed URL from /apps/by-owner to /apps/by-self, removed owner parameter.
CHANGES.md Added release note entry documenting the security fix preventing unauthorized access via /apps/by-owner.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AppController
    participant UserInfoHolder
    participant RoleService
    participant AppService

    User->>AppController: GET /apps/by-self?page=X&size=Y
    AppController->>UserInfoHolder: Get logged-in user ID
    AppController->>RoleService: Get roles for user
    RoleService-->>AppController: Return app IDs
    AppController->>AppService: Query apps by app IDs with pagination
    AppService-->>AppController: Return apps
    AppController-->>User: Return paginated app list
Loading

Assessment against linked issues

Objective Addressed Explanation
Restrict /apps/by-owner endpoint to only allow querying the logged-in user's apps (#5388)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

size:M, lgtm

Poem

🐰 A hop, a skip, a secure new way,
No more peeking where others stray.
Apps by self, the rule is clear,
Safety first, with nothing to fear!
🎉🔐🐇
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34157aa and 3e71220.

📒 Files selected for processing (4)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java (2 hunks)
  • apollo-portal/src/main/resources/static/scripts/controller/IndexController.js (1 hunks)
  • apollo-portal/src/main/resources/static/scripts/services/AppService.js (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • CHANGES.md
  • apollo-portal/src/main/resources/static/scripts/controller/IndexController.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
  • apollo-portal/src/main/resources/static/scripts/services/AppService.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 2, 2025

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@RooobinYe
Copy link
Copy Markdown
Member Author

I have read the CLA Document and I hereby sign the CLA

@RooobinYe
Copy link
Copy Markdown
Member Author

RooobinYe commented Jun 4, 2025

Write necessary unit tests to verify the code.

For this interface, there is no corresponding test file in the project.

@RooobinYe RooobinYe marked this pull request as ready for review June 4, 2025 12:52
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 4, 2025
Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java (1)

108-112: Consider API transparency for parameter override.

The silent override of the owner parameter might be confusing for API consumers. While this approach maintains backward compatibility, consider documenting this behavior in the API documentation or adding a response header indicating when parameter override occurs.

Alternative approaches to consider:

  1. Return an HTTP 403 Forbidden when users try to access other users' apps
  2. Add a response header indicating parameter override
  3. Document the behavior clearly in API documentation
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56ec144 and 2b97f14.

📒 Files selected for processing (2)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/UserInfo.java (1)
  • UserInfo (19-79)
🔇 Additional comments (2)
CHANGES.md (1)

15-15: LGTM! Proper documentation of security fix.

The changelog entry correctly documents the security enhancement with appropriate categorization and PR reference.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java (1)

31-31: LGTM! Appropriate import addition.

The UserInfo import is correctly added to support the security enhancement.

Comment on lines +108 to +112
UserInfo loginUser = userInfoHolder.getUser();
if(!Objects.equals(loginUser.getUserId(), owner)) {
// User can only search his own apps
owner = loginUser.getUserId();
}
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.

⚠️ Potential issue

Critical: Add null safety check for user authentication.

The security logic is sound, but there's a potential NullPointerException if userInfoHolder.getUser() returns null when the user is not properly authenticated.

Apply this diff to add proper null safety:

 public List<App> findAppsByOwner(@RequestParam("owner") String owner, Pageable page) {
   UserInfo loginUser = userInfoHolder.getUser();
+  if (loginUser == null) {
+    throw new BadRequestException("User not authenticated");
+  }
   if(!Objects.equals(loginUser.getUserId(), owner)) {
     // User can only search his own apps
     owner = loginUser.getUserId();
   }

Additionally, consider adding security audit logging when parameter override occurs:

   if(!Objects.equals(loginUser.getUserId(), owner)) {
     // User can only search his own apps
+    // Log security violation attempt for monitoring
     owner = loginUser.getUserId();
   }
📝 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
UserInfo loginUser = userInfoHolder.getUser();
if(!Objects.equals(loginUser.getUserId(), owner)) {
// User can only search his own apps
owner = loginUser.getUserId();
}
public List<App> findAppsByOwner(@RequestParam("owner") String owner, Pageable page) {
UserInfo loginUser = userInfoHolder.getUser();
+ if (loginUser == null) {
+ throw new BadRequestException("User not authenticated");
+ }
if (!Objects.equals(loginUser.getUserId(), owner)) {
// User can only search his own apps
+ // Log security violation attempt for monitoring
owner = loginUser.getUserId();
}
// … rest of method …
}
🤖 Prompt for AI Agents
In
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
around lines 108 to 112, add a null check for loginUser after calling
userInfoHolder.getUser() to prevent NullPointerException if the user is not
authenticated. Only proceed with comparing and overriding owner if loginUser is
not null. Also, add security audit logging to record when the owner parameter is
overridden due to authentication checks.

Copy link
Copy Markdown
Member

@spaceluke spaceluke left a comment

Choose a reason for hiding this comment

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

目前看这个接口只有一个地方使用,不过从语义上来讲,还是可以新增一个获取自己应用列表的接口(不需要传 userid)。
至于老接口,可以删除,不过不确定是否有外部应用依赖这个接口

我认为不应该直接改原本这个接口,应该新增一个比如 /by-self 这样的接口。

旧接口可以更改为需要superadmin权限,或直接删除。 @nobodyiam 哪种比较合适呢?

@nobodyiam
Copy link
Copy Markdown
Member

目前看这个接口只有一个地方使用,不过从语义上来讲,还是可以新增一个获取自己应用列表的接口(不需要传 userid)。
至于老接口,可以删除,不过不确定是否有外部应用依赖这个接口

我认为不应该直接改原本这个接口,应该新增一个比如 /by-self 这样的接口。

旧接口可以更改为需要superadmin权限,或直接删除。 @nobodyiam 哪种比较合适呢?

是的,从语义上来讲新增一个接口更为合适。旧接口可以更改为需要 superadmin 权限,或直接删除。

@RooobinYe
Copy link
Copy Markdown
Member Author

好的 我将重新完成此 pr

@RooobinYe RooobinYe marked this pull request as draft June 5, 2025 03:59
@RooobinYe RooobinYe force-pushed the fix/apps-by-owner-authorization-5388 branch from 4f46e7f to 859817e Compare June 6, 2025 04:09
@RooobinYe RooobinYe marked this pull request as ready for review June 6, 2025 07:20
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 6, 2025
Copy link
Copy Markdown
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 7, 2025
RooobinYe added 4 commits June 7, 2025 11:35
- Restrict /apps/by-owner to super admin users only
- Add new /apps/by-self endpoint for users to access their own apps
- Update frontend to use self-service endpoint for better security
Remove orphaned find_app_by_owner function and resource definition that were no longer used after the /apps/by-owner endpoint removal.
@nobodyiam nobodyiam force-pushed the fix/apps-by-owner-authorization-5388 branch from 34157aa to 3e71220 Compare June 7, 2025 03:35
Copy link
Copy Markdown
Member

@spaceluke spaceluke left a comment

Choose a reason for hiding this comment

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

LGTM

@spaceluke spaceluke merged commit 42b6d98 into apolloconfig:master Jun 8, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2025
@nobodyiam nobodyiam added this to the 2.5.0 milestone Feb 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/apps/by-owner接口越权问题

3 participants