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

Staticcheck fixes / input sanitation #7

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,18 @@ func (a *App) replyRoute(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusInternalServerError, "can't find topic")
return
}
a.db.Create(&model.Message{
message := model.Message{
Content: c.PostForm("reply"),
ReportID: report.ID,
IsAdmin: isAdmin,
})
}
a.db.Create(&message)
err := mail.SendMail(
a.config.Mail.User, a.config.Mail.Password,
a.config.Mail.SMTPServer, a.config.Mail.SMTPPort,
a.config.Mail.FromName, a.config.Mail.From, topic.Email,
fmt.Sprintf("[%s]: report #%d updated", topic.Name.En, report.ID),
"Hi, there is a new message regarding "+topic.Name.En+":\n\n"+c.PostForm("reply")+"\n\nYou can reply to it <a href=\""+a.config.URL+"/report?administratorToken="+report.AdministratorToken+"\">here</a>.")
"Hi, there is a new message regarding "+topic.Name.En+":\n\n"+string(message.GetBody())+"\n\nYou can reply to it <a href=\""+a.config.URL+"/report?administratorToken="+report.AdministratorToken+"\">here</a>.")
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Agreed that this should be done, but it has some implications: Instead of sending the raw message, we now convert it to html and send that. Have you tested that this renders as expected?

if err != nil {
log.Println(err)
}
Expand All @@ -354,7 +355,7 @@ func (a *App) replyRoute(c *gin.Context) {
a.config.Mail.SMTPServer, a.config.Mail.SMTPPort,
a.config.Mail.FromName, a.config.Mail.From, *report.Creator,
fmt.Sprintf("[%s]: report #%d updated", topic.Name.En, report.ID),
"Hi, there is a new message regarding "+topic.Name.En+":\n\n"+c.PostForm("reply")+"\n\nYou can reply to it <a href=\""+a.config.URL+"/report?reporterToken="+report.ReporterToken+"\">here</a>.")
"Hi, there is a new message regarding "+topic.Name.En+":\n\n"+string(message.GetBody())+"\n\nYou can reply to it <a href=\""+a.config.URL+"/report?reporterToken="+report.ReporterToken+"\">here</a>.")
if err != nil {
log.Println(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/middleware/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func generateKey(org, country, province, locality, streetAddress, postalCode, cn
return err
}
defer file.Close()
_, err = file.Write(caPEM.Bytes())
file.Write(caPEM.Bytes())
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

tbh we should do something with the err


caPrivKeyPEM := new(bytes.Buffer)
err = pem.Encode(caPrivKeyPEM, &pem.Block{
Expand All @@ -72,6 +72,6 @@ func generateKey(org, country, province, locality, streetAddress, postalCode, cn
return err
}
defer keyF.Close()
_, err = keyF.Write(caPrivKeyPEM.Bytes())
keyF.Write(caPrivKeyPEM.Bytes())
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Here as well, even if just returning it

return nil
}
2 changes: 1 addition & 1 deletion pkg/model/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (m *MatrixMessenger) SendMessage(title string, message Message, reportURL s
if err != nil {
return err
}
resp, err := http.Post(
resp, _ := http.Post(
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Let's not ignore errors, return them instead

fmt.Sprintf(matrixMSGApiURL, m.config.HomeServer, m.config.RoomID, m.config.AccessToken),
"application/json",
bytes.NewBuffer(marshal),
Expand Down