Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b088640e9b | |||
| 26847f1e9f | |||
| 50033a5bd4 | |||
| 01c622038d |
@@ -9,7 +9,7 @@
|
||||
<Description>RabbitMQ message contracts for HrynCo.NotificationService.</Description>
|
||||
<PackageTags>hrynco notification email rabbitmq contracts</PackageTags>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://gitea.grynco.com.ua/hrynco/hrynco-notification-service.git</RepositoryUrl>
|
||||
<RepositoryUrl>https://gitea.hrynco.com/hrynco/hrynco-notification-service.git</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+21
@@ -40,6 +40,27 @@ public sealed class EmailTemplateRenderingServiceTests
|
||||
Assert.Equal("Required template variables are missing: VerificationUrl.", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Render_HtmlEncodesVariablesWithoutChangingSubjectOrTextBody()
|
||||
{
|
||||
EmailTemplate template = CreateTemplate();
|
||||
SendEmailMessageData data = CreateData(new Dictionary<string, string>
|
||||
{
|
||||
["AppName"] = "Invemory <script>alert('xss')</script>",
|
||||
["VerificationUrl"] = "https://example.invalid/verify?next=\" onclick=\"alert('xss')"
|
||||
});
|
||||
|
||||
RenderedEmail result = _service.Render(template, data);
|
||||
|
||||
Assert.Equal("Verify Invemory <script>alert('xss')</script>", result.Subject);
|
||||
Assert.Equal(
|
||||
"<a href=\"https://example.invalid/verify?next=" onclick="alert('xss')\">Verify</a>",
|
||||
result.HtmlBody);
|
||||
Assert.Equal(
|
||||
"Verify at https://example.invalid/verify?next=\" onclick=\"alert('xss')",
|
||||
result.TextBody);
|
||||
}
|
||||
|
||||
private static EmailTemplate CreateTemplate() => new()
|
||||
{
|
||||
ServiceName = "StoreMate-Prod",
|
||||
|
||||
+16
-2
@@ -1,5 +1,6 @@
|
||||
namespace HrynCo.NotificationService.Worker.Services.EmailProcessing;
|
||||
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using HrynCo.NotificationService.Contracts.Messages;
|
||||
using HrynCo.NotificationService.DAL.Abstract.Templates;
|
||||
@@ -22,15 +23,28 @@ internal sealed class EmailTemplateRenderingService : IEmailTemplateRenderingSer
|
||||
|
||||
return new RenderedEmail(
|
||||
Interpolate(template.Subject, data.Variables),
|
||||
Interpolate(template.HtmlBody, data.Variables),
|
||||
InterpolateHtml(template.HtmlBody, data.Variables),
|
||||
Interpolate(template.TextBody, data.Variables));
|
||||
}
|
||||
|
||||
private static string InterpolateHtml(string text, IReadOnlyDictionary<string, string> variables)
|
||||
{
|
||||
return Interpolate(text, variables, WebUtility.HtmlEncode);
|
||||
}
|
||||
|
||||
private static string Interpolate(string text, IReadOnlyDictionary<string, string> variables)
|
||||
{
|
||||
return Interpolate(text, variables, static value => value);
|
||||
}
|
||||
|
||||
private static string Interpolate(
|
||||
string text,
|
||||
IReadOnlyDictionary<string, string> variables,
|
||||
Func<string, string> encodeValue)
|
||||
{
|
||||
var sb = new StringBuilder(text);
|
||||
foreach (var (key, value) in variables)
|
||||
sb.Replace($"{{{{{key}}}}}", value);
|
||||
sb.Replace($"{{{{{key}}}}}", encodeValue(value));
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# hrynco-notification-service
|
||||
|
||||
Production image references now use `registry.hrynco.com`, preserving the existing image-tag variables. Contracts package repository metadata uses `gitea.hrynco.com`. These are source configuration changes; production containers and live CI configuration were not restarted or updated by this migration.
|
||||
|
||||
## Documentation
|
||||
|
||||
- [ItemTracker outbox email consumer](docs/itemtracker-outbox-email-consumer.md)
|
||||
@@ -112,3 +114,7 @@ flowchart TD
|
||||
M -->|retries exhausted| N[Publish terminal failure result]
|
||||
N --> O[Nack original delivery without requeue]
|
||||
```
|
||||
|
||||
Template variables are treated as plain text. The worker HTML-encodes every variable while
|
||||
rendering `HtmlBody`; subject and plain-text body interpolation preserve the original value.
|
||||
Templates must express markup in `body.html` instead of supplying HTML through variables.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
services:
|
||||
migrator:
|
||||
build: {}
|
||||
image: registry.grynco.com.ua/hrynco.notification-service.migrator:${MIGRATOR_IMAGE_TAG:?MIGRATOR_IMAGE_TAG is required}
|
||||
image: registry.hrynco.com/hrynco.notification-service.migrator:${MIGRATOR_IMAGE_TAG:?MIGRATOR_IMAGE_TAG is required}
|
||||
|
||||
web:
|
||||
build: {}
|
||||
image: registry.grynco.com.ua/hrynco.notification-service.web:${WEB_IMAGE_TAG:?WEB_IMAGE_TAG is required}
|
||||
image: registry.hrynco.com/hrynco.notification-service.web:${WEB_IMAGE_TAG:?WEB_IMAGE_TAG is required}
|
||||
ports:
|
||||
- "${WEB_PORT:?WEB_PORT is required}:8080"
|
||||
environment:
|
||||
@@ -14,7 +14,7 @@ services:
|
||||
|
||||
worker:
|
||||
build: {}
|
||||
image: registry.grynco.com.ua/hrynco.notification-service.worker:${WORKER_IMAGE_TAG:?WORKER_IMAGE_TAG is required}
|
||||
image: registry.hrynco.com/hrynco.notification-service.worker:${WORKER_IMAGE_TAG:?WORKER_IMAGE_TAG is required}
|
||||
environment:
|
||||
- Serilog__WriteTo__1__Args__serverUrl=${SEQ_URL:-}
|
||||
restart: always
|
||||
|
||||
Reference in New Issue
Block a user