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

[CCAP-493] Create sendGrid family confirmation email and background job #970

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

spokenbird
Copy link
Contributor

🔗 Jira ticket

CCAP-493

✍️ Description

Creates a SendGridEmailService and background job which is enqueued via an action. The action queue's a background job to send an email via the sendgrid API.

@enyia21 enyia21 temporarily deployed to il-gcc-ccap-493-family--n4tpgk December 23, 2024 21:48 Inactive
@spokenbird spokenbird temporarily deployed to il-gcc-ccap-493-family--n4tpgk December 23, 2024 23:11 Inactive
@spokenbird spokenbird temporarily deployed to il-gcc-ccap-493-family--n4tpgk December 24, 2024 19:17 Inactive
@spokenbird spokenbird temporarily deployed to il-gcc-ccap-493-family--n4tpgk December 24, 2024 19:32 Inactive
@spokenbird spokenbird force-pushed the ccap-493-family-confirmation-email branch from 42994ee to 76c5aab Compare December 24, 2024 19:36
@spokenbird spokenbird temporarily deployed to il-gcc-ccap-493-family--n4tpgk December 24, 2024 19:37 Inactive
return;
}

log.info("Received {} SendGrid events", events);

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.

Copilot Autofix AI 12 days ago

To fix the log injection issue, we need to sanitize the events parameter before logging it. The best way to do this is to remove any potentially dangerous characters, such as new-line characters, from the user-provided data. We can achieve this by converting the events list to a sanitized string representation before logging it.

  1. Create a method to sanitize the events parameter by removing new-line characters.
  2. Use this method to sanitize the events parameter before logging it.
Suggested changeset 1
src/main/java/org/ilgcc/app/email/SendGridWebhookController.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/org/ilgcc/app/email/SendGridWebhookController.java b/src/main/java/org/ilgcc/app/email/SendGridWebhookController.java
--- a/src/main/java/org/ilgcc/app/email/SendGridWebhookController.java
+++ b/src/main/java/org/ilgcc/app/email/SendGridWebhookController.java
@@ -45,3 +45,13 @@
 
-        log.info("Received {} SendGrid events", events);
+        log.info("Received {} SendGrid events", sanitizeEvents(events));
+    }
+
+    /**
+     * Sanitize the events list by removing new-line characters.
+     *
+     * @param events: list of events to sanitize
+     * @return a sanitized string representation of the events
+     */
+    private String sanitizeEvents(List<Map<String, Object>> events) {
+        return events.toString().replaceAll("[\\r\\n]", "");
     }
EOF
@@ -45,3 +45,13 @@

log.info("Received {} SendGrid events", events);
log.info("Received {} SendGrid events", sanitizeEvents(events));
}

/**
* Sanitize the events list by removing new-line characters.
*
* @param events: list of events to sanitize
* @return a sanitized string representation of the events
*/
private String sanitizeEvents(List<Map<String, Object>> events) {
return events.toString().replaceAll("[\\r\\n]", "");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@spokenbird spokenbird temporarily deployed to il-gcc-ccap-493-family--n4tpgk December 24, 2024 20:03 Inactive
@spokenbird
Copy link
Contributor Author

@cram-cfa
I've left this PR in a state where the sendgrid email functionality is fully working. The email will be sent when a user submits the contact-provider-message screen, to the email they entered in the flow.

Not fully implemented is the webhook which I haven't been able to get working. The webhook should provide asynchronous updates on email statuses from Sendgrid, to our applications endpoint. I can see pings to the endpoint in the Heroku logs, but the endpoint shows a 403 (unauthorized?) which I'm not sure if that means our application is saying Heroku is unauthorized or vice versa.

https://www.twilio.com/docs/sendgrid/for-developers/tracking-events/getting-started-event-webhook

https://www.twilio.com/docs/sendgrid/for-developers/tracking-events/getting-started-event-webhook-security-features

If we can get this working we should be able to implement retries when needed and a status table for emails.

@spokenbird
Copy link
Contributor Author

I also setup a Datadog alert if communicating with Sendgrid fails:
https://app.datadoghq.com/monitors/161103803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants