Updated site info feed and search service

Modified site info feed template to secure the description field against injected code. Also adjusted search service by extracting samples within the correct scope and including them in the returned site info. This improves the quality and security of the displayed information.
This commit is contained in:
Viktor Lofgren 2023-12-26 22:06:01 +01:00
parent 1694e9c78c
commit 5d1b7da728
3 changed files with 29 additions and 11 deletions

View File

@ -9,4 +9,9 @@ public record FeedItem(String title, String date, String description, String url
return date; return date;
} }
public String descriptionSafe() {
return description
.replace("<", "&lt;")
.replace(">", "&gt;");
}
} }

View File

@ -131,7 +131,6 @@ public class SearchSiteInfoService {
String url = "https://" + domainName + "/";; String url = "https://" + domainName + "/";;
var feedItemsFuture = feedlotClient.getFeedItems(domainName); var feedItemsFuture = feedlotClient.getFeedItems(domainName);
if (domainId < 0 || !assistantClient.isAccepting()) { if (domainId < 0 || !assistantClient.isAccepting()) {
domainInfo = createDummySiteInfo(domainName); domainInfo = createDummySiteInfo(domainName);
similarSet = List.of(); similarSet = List.of();
@ -145,12 +144,12 @@ public class SearchSiteInfoService {
linkingDomains = assistantClient linkingDomains = assistantClient
.linkedDomains(ctx, domainId, 100) .linkedDomains(ctx, domainId, 100)
.blockingFirst(); .blockingFirst();
}
List<UrlDetails> sampleResults = searchOperator.doSiteSearch(ctx, domainName, 1); List<UrlDetails> sampleResults = searchOperator.doSiteSearch(ctx, domainName, 5);
if (!sampleResults.isEmpty()) { if (!sampleResults.isEmpty()) {
url = sampleResults.getFirst().url.withPathAndParam("/", null).toString(); url = sampleResults.getFirst().url.withPathAndParam("/", null).toString();
} }
}
FeedItems feedItems = null; FeedItems feedItems = null;
try { try {
@ -165,7 +164,8 @@ public class SearchSiteInfoService {
domainInfo, domainInfo,
similarSet, similarSet,
linkingDomains, linkingDomains,
feedItems feedItems,
sampleResults
); );
} }
@ -220,7 +220,8 @@ public class SearchSiteInfoService {
DomainInformation domainInformation, DomainInformation domainInformation,
List<SimilarDomain> similar, List<SimilarDomain> similar,
List<SimilarDomain> linking, List<SimilarDomain> linking,
FeedItems feed FeedItems feed,
List<UrlDetails> samples
) { ) {
public SiteInfoWithContext(String domain, public SiteInfoWithContext(String domain,
long domainId, long domainId,
@ -228,7 +229,8 @@ public class SearchSiteInfoService {
DomainInformation domainInformation, DomainInformation domainInformation,
List<SimilarDomain> similar, List<SimilarDomain> similar,
List<SimilarDomain> linking, List<SimilarDomain> linking,
FeedItems feedInfo FeedItems feedInfo,
List<UrlDetails> samples
) )
{ {
this(Map.of("info", true), this(Map.of("info", true),
@ -239,7 +241,8 @@ public class SearchSiteInfoService {
domainInformation, domainInformation,
similar, similar,
linking, linking,
feedInfo); feedInfo,
samples);
} }
public String getLayout() { public String getLayout() {

View File

@ -4,7 +4,17 @@
<dl> <dl>
{{#each items}} {{#each items}}
<dt><a href="{{url}}" rel="external noopener ugc">{{title}}</a></dt> <dt><a href="{{url}}" rel="external noopener ugc">{{title}}</a></dt>
<dd><date>{{pubDay}}</date><br>{{{description}}}</dd> <dd><date>{{pubDay}}</date><br>{{{descriptionSafe}}}</dd>
{{/each}} {{/each}}
</dl> </dl>
{{/with}} {{/with}}
{{#unless feed}}{{#if samples}}
<h2>Sample</h2>
<dl>
{{#each samples}}
<dt><a href="{{url}}" rel="external noopener ugc">{{title}}</a></dt>
<dd>{{{description}}}</dd>
{{/each}}
</dl>
{{/if}}{{/unless}}