Compare commits

...

4 Commits

Author SHA1 Message Date
agrynco b088640e9b chore(notification): update service host references
Point production image and package metadata references to hrynco.com.

Ref: IT-1493
2026-10-02 20:18:18 +03:00
agrynco 26847f1e9f Merge pull request 'fix: escape html notification variables' (#18) from feature/it-1115-html-template-escaping into main
Reviewed-on: #18
2026-08-19 23:07:03 +03:00
agrynco 50033a5bd4 fix: escape html notification variables
Encode template variables in HTML bodies while preserving text and subjects.

Ref: IT-1115
2026-08-19 23:04:15 +03:00
agrynco 01c622038d Merge pull request 'fix: correct notification template filter links' (#15) from bugfix/it-1039-template-filter-links into main
Reviewed-on: https://gitea.grynco.com.ua/hrynco/hrynco-notification-service/pulls/15
2026-08-04 21:02:59 +03:00
5 changed files with 47 additions and 6 deletions
@@ -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>
@@ -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=&quot; onclick=&quot;alert(&#39;xss&#39;)\">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",
@@ -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();
}
}
+6
View File
@@ -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.
+3 -3
View File
@@ -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