Skip to content

Commit cca626a

Browse files
committed
* remove moderationRepo from commentHandler
* add msg to prevent users to set their email address public * prevent header injection
1 parent 60c6529 commit cca626a

6 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/comment_handler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ type CommentHandler struct {
1414
recordRepo RecordRepository
1515
adminRepo AdminRepository
1616
notificationService *NotificationService
17-
moderationRepo ModerationRepository
1817
}
1918

20-
func NewCommentHandler(commentRepo CommentRepository, recordRepo RecordRepository, adminRepo AdminRepository, notificationService *NotificationService, moderationRepo ModerationRepository) *CommentHandler {
19+
func NewCommentHandler(commentRepo CommentRepository, recordRepo RecordRepository, adminRepo AdminRepository, notificationService *NotificationService) *CommentHandler {
2120
return &CommentHandler{
2221
commentRepo: commentRepo,
2322
recordRepo: recordRepo,
2423
adminRepo: adminRepo,
2524
notificationService: notificationService,
26-
moderationRepo: moderationRepo,
2725
}
2826
}
2927

src/email_sender.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net"
66
"net/smtp"
77
"os"
8+
"strings"
89
)
910

1011
type EmailSender struct {
@@ -26,13 +27,17 @@ func NewEmailSender() *EmailSender {
2627
}
2728

2829
func (e *EmailSender) Send(to string, subject string, body string) error {
30+
// Sanitize 'to' to prevent header injection
31+
if strings.ContainsAny(to, "\r\n") {
32+
return fmt.Errorf("email sender: recipient address contains invalid CRLF characters")
33+
}
2934
var smtpAddr = net.JoinHostPort(e.smtpHost, e.smtpPort)
3035

3136
auth := smtp.PlainAuth("", e.smtpUsername, e.smtpPassword, e.smtpHost)
3237
recipients := []string{to}
3338
msg := []byte(
3439
"From: " + e.smtpFromAddress + "\r\n" +
35-
"To: " + to + "\r\n" +
40+
"To: " + to +
3641
"Subject: " + subject + "\r\n" +
3742
"MIME-Version: 1.0\r\n" +
3843
"Content-Type: text/plain; charset=\"UTF-8\"\r\n" +

src/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func main() {
477477
emailWorker := NewEmailWorker(emailQueueRepo, emailSender, orcidService)
478478
moderationRepo := NewPostgresModerationRepository(db, categoryRepo, rorRepo)
479479
moderationHandler := NewModerationHandler(moderationRepo, adminRepo, notificationService, recordRepo)
480-
commentHandler := NewCommentHandler(commentRepo, recordRepo, adminRepo, notificationService, moderationRepo)
480+
commentHandler := NewCommentHandler(commentRepo, recordRepo, adminRepo, notificationService)
481481

482482
// Initialize ROR handler with name cache
483483
rorHandler := NewRorHandler()

src/record_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,8 +1097,8 @@ func (r *PostgresRecordRepository) IncrementDownloadCount(ctx context.Context, i
10971097
func (r *PostgresRecordRepository) GetOwnerOrcid(ctx context.Context, recordID string) (string, error) {
10981098
var uploaderOrcid string
10991099
err := r.db.QueryRowContext(ctx, "SELECT uploader_orcid FROM records WHERE id = $1", recordID).Scan(&uploaderOrcid)
1100-
if err != nil {
1101-
return "", err
1100+
if err == sql.ErrNoRows {
1101+
return "", ErrRecordNotFound
11021102
}
11031103
return uploaderOrcid, nil
11041104
}

src/sql/014_add_email_queue.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Queue of email notifications to be sent for record and comment moderation events
22
CREATE TABLE IF NOT EXISTS email_queue (
33
id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
4-
record_id UUID NOT NULL REFERENCES records(id),
4+
record_id UUID NOT NULL REFERENCES records(id) ON DELETE CASCADE,
55
comment_id BIGINT REFERENCES comments(id) ON DELETE SET NULL,
66
recipient_orcid orcid_type NOT NULL,
77
subject TEXT NOT NULL,

src/templates/browse.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{{ define "content" }}
44
<div class="mt-4 alert alert-info alert-dismissible" role="alert">
5-
Welcome to the template sharing site, this is still in <b>Beta mode</b>. For more informations, please see the <a href="/about">About</a> page.<br>Thank you for helping us to test so that we can open the site.
5+
Welcome to the template sharing site, this is still in <b>Beta mode</b>. For more informations, please see the <a href="/about">About</a> page.<br>Please note that we does not store your email address. To receive notifications, please make sure your email address is set as <b>public</b> on orcid.org<br><br>Thank you for helping us to test so that we can open the site.
66
</div>
77
<div class="row">
88
<h2 class="col-md-12">Browse entries</h2>

0 commit comments

Comments
 (0)