Panic in template rendering causes dumping of panic in to response #6790

Closed
opened 2025-11-02 07:06:38 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @CirnoT on GitHub (Jan 30, 2021).

  • Gitea version (or commit ref): 1.14.0+dev-642-g0e0424c8e
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:
2021/01/30 11:16:48 ...els/issue_comment.go:382:LoadLabel() [W] Commit 922 cannot load label 0
2021/01/30 11:16:48 ...els/issue_comment.go:382:LoadLabel() [W] Commit 958 cannot load label 0
2021/01/30 11:16:48 ...els/issue_comment.go:382:LoadLabel() [W] Commit 961 cannot load label 0
2021/01/30 11:16:48 ...s/context/context.go:191:HTML() [E] Render failed: template: repo/issue/view_content/comments:188:51: executing "repo/issue/view_content/comments" at <RenderLabels .AddedLabels>: error calling RenderLabels: runtime error: invalid memory address or nil pointer dereference
2021/01/30 11:16:48 ...c/net/http/server.go:3095:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64)

Description

Template render errors cause HTML content of Internal Server Error page being displayed as text/plain along with full panic message.

Originally created by @CirnoT on GitHub (Jan 30, 2021). - Gitea version (or commit ref): 1.14.0+dev-642-g0e0424c8e - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [x] No - Log gist: ``` 2021/01/30 11:16:48 ...els/issue_comment.go:382:LoadLabel() [W] Commit 922 cannot load label 0 2021/01/30 11:16:48 ...els/issue_comment.go:382:LoadLabel() [W] Commit 958 cannot load label 0 2021/01/30 11:16:48 ...els/issue_comment.go:382:LoadLabel() [W] Commit 961 cannot load label 0 2021/01/30 11:16:48 ...s/context/context.go:191:HTML() [E] Render failed: template: repo/issue/view_content/comments:188:51: executing "repo/issue/view_content/comments" at <RenderLabels .AddedLabels>: error calling RenderLabels: runtime error: invalid memory address or nil pointer dereference 2021/01/30 11:16:48 ...c/net/http/server.go:3095:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64) ``` ## Description Template render errors cause HTML content of `Internal Server Error` page being displayed as `text/plain` along with full panic message.
GiteaMirror added the type/bugreviewed/wontfix labels 2025-11-02 07:06:38 -06:00
Author
Owner

@CirnoT commented on GitHub (Jan 30, 2021):

Related to #14466

@CirnoT commented on GitHub (Jan 30, 2021): Related to #14466
Author
Owner

@zeripath commented on GitHub (Feb 9, 2021):

This will be due to the panic writing a header and the original template renderer writing a header.

Unfortunately I don't think there is likely to be a solution here. You have to write the header before you start writing the template but if there is a panic in the template then the panic handler will attempt to write the header again.

So I think we're just gonna have to accept this one as a wontfix

@zeripath commented on GitHub (Feb 9, 2021): This will be due to the panic writing a header and the original template renderer writing a header. Unfortunately I don't think there is likely to be a solution here. You have to write the header before you start writing the template but if there is a panic in the template then the panic handler will attempt to write the header again. So I think we're just gonna have to accept this one as a wontfix
Author
Owner

@CirnoT commented on GitHub (Feb 10, 2021):

Are you sure that is correct? Do we really want that if panic occurs during template rendering, the error page's HTML content is dumped as text/plain (so not rendered as HTML)? That seems kind of a weird. Also I really don't think panic message should be exposed to user in production mode.

@CirnoT commented on GitHub (Feb 10, 2021): Are you sure that is correct? Do we really want that if panic occurs during template rendering, the error page's HTML content is dumped as `text/plain` (so not rendered as HTML)? That seems kind of a weird. Also I really don't think panic message should be exposed to user in production mode.
Author
Owner

@zeripath commented on GitHub (Feb 11, 2021):

@CirnoT your original message was about the writeheader log message - not about it being dumped as plain text. WriteHeader will always have to happen.

I'll reopen. It's really really helpful if the issue is clear from the start as to what the real problem is.

@zeripath commented on GitHub (Feb 11, 2021): @CirnoT your original message was about the writeheader log message - not about it being dumped as plain text. WriteHeader will always have to happen. I'll reopen. It's really really helpful if the issue is clear from the start as to what the real problem is.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#6790