Skip to content

Fix 502 Bad Gateway caused by print() in LuCI template#14075

Open
lushangkan wants to merge 1 commit into
coolsnowwolf:masterfrom
lushangkan:master
Open

Fix 502 Bad Gateway caused by print() in LuCI template#14075
lushangkan wants to merge 1 commit into
coolsnowwolf:masterfrom
lushangkan:master

Conversation

@lushangkan

Copy link
Copy Markdown

Problem

The template renders the wireless profile into a <textarea> using Lua's print():

for line in fd:lines() do
    print(line)
end

print() writes to stdout instead of the LuCI template output stream. On recent LuCI/uCode based systems, this corrupts the CGI response and causes:

502 Bad Gateway
The process did not produce any response

Reason

Older LuCI environments tolerated or redirected print() differently, but recent LuCI/uCode based systems expose this issue because print() writes to the CGI stdout instead of the template output stream.

Steps to reproduce:

  1. Open Wireless Parameters (Raw Configuration)
  2. The page returns:
502 Bad Gateway
The process did not produce any response

Cause:

Lua print() is used inside a LuCI template, which writes to stdout and breaks the HTTP response.

Fix

Instead of printing each line with print(), read the file into a string and render it using LuCI template output (<%= ... %>). This avoids writing directly to stdout and is compatible with both legacy and current LuCI implementations.

@lushangkan lushangkan changed the title luci-app-mtk: replace print() with template output when rendering Fix 502 Bad Gateway caused by print() in LuCI template Jun 28, 2026
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.

1 participant