Skip to content

Commit df63099

Browse files
committed
Exclude hidden RSS fragment content
1 parent a0578e3 commit df63099

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

x-pack/solutions/security/plugins/security_solution/server/threat_intel/adapters/rss/html_fragment_to_structured_text.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ describe('htmlFragmentToStructuredText', () => {
5858
}
5959
);
6060

61+
it('removes hidden subtrees while preserving token boundaries', () => {
62+
expect(htmlFragmentToStructuredText('<p>left<span hidden>secret.example</span>right</p>')).toBe(
63+
'left\nright'
64+
);
65+
});
66+
6167
it('tolerates malformed fragments and plain text', () => {
6268
expect(htmlFragmentToStructuredText('<p>unclosed <b>bold')).toBe('unclosed bold');
6369
expect(htmlFragmentToStructuredText('just plain text with 8.8.8.8')).toBe(

x-pack/solutions/security/plugins/security_solution/server/threat_intel/adapters/rss/html_fragment_to_structured_text.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface DomNode {
5353
type: string;
5454
data?: string;
5555
name?: string;
56+
attribs?: Record<string, string>;
5657
children?: DomNode[];
5758
}
5859

@@ -71,7 +72,9 @@ const stepNode = (node: DomNode, output: string[], stack: WalkStep[]): void => {
7172
}
7273

7374
const name = typeof node.name === 'string' ? node.name.toLowerCase() : undefined;
74-
if (name === 'br' || (name !== undefined && NON_CONTENT_TAGS.has(name))) {
75+
const isHidden =
76+
node.attribs !== undefined && Object.prototype.hasOwnProperty.call(node.attribs, 'hidden');
77+
if (name === 'br' || isHidden || (name !== undefined && NON_CONTENT_TAGS.has(name))) {
7578
output.push('\n');
7679
return;
7780
}

0 commit comments

Comments
 (0)