Skip to content

SwaggerUI requests favicon files with relative paths causing 500 errors #677

@gtolarc

Description

@gtolarc

Description

When accessing SwaggerUI at /api/v1/swagger, the browser automatically requests favicon files using relative paths, which results in requests to /api/v1/favicon-16x16.png and similar endpoints.
These requests are then forwarded to the application router, causing 500 errors.

Environment

  • OpenApiSpex version: 3.21.5
  • Phoenix version: 1.8.0-rc.4
  • Elixir version: 1.18.4
  • Browser: Chrome 138.0.0.0

Steps to Reproduce

  1. Set up a Phoenix application with OpenApiSpex SwaggerUI:
    scope "/api/v1" do
    pipe_through [:api]
forward "/swagger", OpenApiSpex.Plug.SwaggerUI,
  path: "/api/v1/open_api",
  default_model_expand_depth: 4,
  operations_sorter: "alpha",
  tags_sorter: "alpha"

forward "/", MyApp.ApiRouter

end

  1. Navigate to /api/v1/swagger in a browser
  2. Check the browser's network tab and server logs

Expected Behavior

SwaggerUI should either:

  • Use absolute paths for favicon requests (e.g., /favicon-16x16.png instead of favicon-16x16.png)
  • Not request favicon files at all
  • Include its own favicon handling

Actual Behavior

The browser requests:

  • /api/v1/favicon-16x16.png
  • /api/v1/favicon-32x32.png
  • /api/v1/favicon.ico
Image

These requests are forwarded to the application's API router, causing errors like:
[error] ** (UndefinedFunctionError) function MyApp.Domain.json_api_match_route/2 is undefined or private

Error Log

2025-07-30 10:17:57.849 request_id=GFbinxHb7U2mY28AABkB remote_ip=127.0.0.1 user_agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0
Safari/537.36 [error] ** (UndefinedFunctionError) function MyApp.Accounts.json_api_match_route/2 is undefined or private
(my_app 0.1.0) MyApp.Accounts.json_api_match_route("GET", ["favicon-16x16.png"])
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions