Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 16ee726

Browse files
committed
fix(blog): replace iterative HTML tag stripping with single-pass angle bracket removal
The CodeQL scanner flagged the iterative stripHtmlTags function for incomplete multi-character sanitization. The regex /<[^>]+>/g only matches complete tags, so partial fragments like <script (without a closing >) could survive intermediate loop iterations. Since this function is only used for word counting in calculateReadingTime, replace the multi-step approach with a simple single-pass removal of all < and > characters. This eliminates the incomplete sanitization pattern entirely.
1 parent a840b07 commit 16ee726

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

  • apps/web-roo-code/src/lib/blog

apps/web-roo-code/src/lib/blog/time.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,14 @@ export function formatPostDatePt(publishDate: string): string {
9898
}
9999

100100
/**
101-
* Repeatedly strip HTML tags until no more remain.
102-
* A single-pass replacement is vulnerable to incomplete sanitization when
103-
* the input contains nested/split patterns like `<scr<script>ipt>`.
101+
* Strip all angle brackets from text to remove any HTML tags or fragments.
102+
* This is used only for word-count purposes in reading-time calculation,
103+
* so a single-pass removal of every `<` and `>` is sufficient and
104+
* avoids the incomplete multi-character sanitization pattern that
105+
* iterative tag-stripping is vulnerable to.
104106
*/
105107
function stripHtmlTags(text: string): string {
106-
const TAG_RE = /<[^>]+>/g
107-
let previous = text
108-
let result = text.replace(TAG_RE, "")
109-
while (result !== previous) {
110-
previous = result
111-
result = result.replace(TAG_RE, "")
112-
}
113-
// Final safety: remove any remaining angle brackets
114-
return result.replace(/[<>]/g, "")
108+
return text.replace(/[<>]/g, "")
115109
}
116110

117111
/**

0 commit comments

Comments
 (0)