Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 404 for everything we don't know #10996

Conversation

sstrigler
Copy link
Contributor

@sstrigler sstrigler commented Jun 9, 2023

Fixes EMQX-9435

Summary

🤖 Generated by Copilot at b561dc6

Removed the emqx_dashboard_swagger handler and improved the emqx_dashboard_404 handler and its test module. This change enhances the security and usability of the dashboard by hiding the swagger API documentation and providing different 404 responses based on the request content type.

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Changed lines covered in coverage report
  • Change log has been added to changes/{ce,ee}/(feat|perf|fix)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • If there should be document changes, a PR to emqx-docs.git is sent, or a jira ticket is created to follow up
  • Schema changes are backward compatible

@sstrigler sstrigler marked this pull request as ready for review June 9, 2023 13:33
@sstrigler sstrigler requested review from a team, JimMoen and lafirest as code owners June 9, 2023 13:33
ct_body(<<"text/plain">>) ->
<<"404 - NOT FOUND">>;
ct_body(<<"application/json">>) ->
<<"{\"code\": \"API_NOT_EXIST\", \"message\": \"Request Path Not Found\"}">>.
Copy link
Member

@ieQu1 ieQu1 Jun 9, 2023

Choose a reason for hiding this comment

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

Better grammar:

Suggested change
<<"{\"code\": \"API_NOT_EXIST\", \"message\": \"Request Path Not Found\"}">>.
<<"{\"code\": \"NOT_FOUND\", \"message\": \"Request Path Not Found\"}">>.

ieQu1
ieQu1 previously approved these changes Jun 9, 2023
@sstrigler sstrigler force-pushed the EMQX-9435-request-the-non-existent-api-v-4-nodes-endpoint-in-emqx-e-5-0-1-returns-http-code-200 branch 3 times, most recently from 0dafd18 to 30cceef Compare June 9, 2023 13:47
Copy link
Contributor

@kjellwinblad kjellwinblad left a comment

Choose a reason for hiding this comment

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

LGTM

@sstrigler sstrigler force-pushed the EMQX-9435-request-the-non-existent-api-v-4-nodes-endpoint-in-emqx-e-5-0-1-returns-http-code-200 branch from 30cceef to 8c1334c Compare June 9, 2023 15:13
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 5223389504

  • 3 of 7 (42.86%) changed or added relevant lines in 1 file are covered.
  • 34 unchanged lines in 13 files lost coverage.
  • Overall coverage decreased (-0.02%) to 81.911%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/emqx_dashboard/src/emqx_dashboard_not_found.erl 3 7 42.86%
Files with Coverage Reduction New Missed Lines %
apps/emqx_connector/src/emqx_connector_jwt_worker.erl 1 89.47%
apps/emqx_dashboard/src/emqx_dashboard_monitor.erl 1 66.21%
apps/emqx_ft/src/emqx_ft_storage_exporter_fs.erl 1 78.26%
apps/emqx_gateway_mqttsn/src/emqx_mqttsn_frame.erl 1 62.92%
apps/emqx_gateway/src/emqx_gateway_schema.erl 1 94.44%
apps/emqx/src/emqx_logger.erl 1 80.49%
apps/emqx/src/emqx_metrics.erl 1 88.21%
apps/emqx_resource/src/emqx_resource_buffer_worker.erl 2 92.96%
apps/emqx/src/emqx_channel.erl 2 87.86%
apps/emqx/src/emqx_cm.erl 2 92.47%
Totals Coverage Status
Change from base Build 5223381829: -0.02%
Covered Lines: 29659
Relevant Lines: 36209

💛 - Coveralls

@zmstone zmstone merged commit 3901ed3 into emqx:master Jun 10, 2023
131 of 132 checks passed
@yanzhiemq
Copy link
Collaborator

yanzhiemq commented Jun 13, 2023

Bug Fixes

  • For any unknown HTTP/API request, the default response is a 404 error rather than the dashboard's index.html.

@yanzhiemq
Copy link
Collaborator

yanzhiemq commented Jun 13, 2023

修复

  • 对于任何未知的 HTTP/API 请求,默认返回404错误,而不是返回 Dashboard 的 index.html 页面。

@sstrigler sstrigler deleted the EMQX-9435-request-the-non-existent-api-v-4-nodes-endpoint-in-emqx-e-5-0-1-returns-http-code-200 branch October 25, 2023 08:47
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.

None yet

6 participants