github-advanced-security[bot] commented on code in PR #6451:
URL: https://github.com/apache/myfaces-tobago/pull/6451#discussion_r2106795170


##########
tobago-example/tobago-example-demo/src/main/webapp/js/demo-sidebar.js:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+export class Sidebar extends HTMLElement {
+    connectedCallback() {
+        if (this.fixedHeader) {
+            const resizeObserver = new ResizeObserver(() => {
+                const headerHeight = this.fixedHeader.offsetHeight;
+                const headerMarginBottom = 
parseFloat(getComputedStyle(this.fixedHeader).marginBottom);
+                this.rootHtml.style.scrollPaddingTop = headerHeight + 
headerMarginBottom + "px";
+                this.style.top = headerHeight + "px";
+            });
+            resizeObserver.observe(this.fixedHeader);
+        }
+        if (this.fixedFooter) {
+            const resizeObserver = new ResizeObserver(() => this.style.bottom 
= this.fixedFooter.offsetHeight + "px");
+            resizeObserver.observe(this.fixedFooter);
+        }
+        this.insertAdjacentHTML("afterbegin", "<strong>On this 
page</strong><nav id='tableOfContents'></nav>");
+        this.sectionTree = {
+            id: this.rootSection.id,
+            title: this.getSectionTitle(this.rootSection),
+            level: 0,
+            children: []
+        };
+        this.buildSectionTree(this.rootSection, this.sectionTree);
+        this.renderTableOfContent(this.sectionTree, this.tableOfContentsNav);
+        this.updateActiveNavLink();
+        this.scrollEventListener = this.scrollEvent.bind(this);
+        window.addEventListener("scroll", this.scrollEventListener);
+    }
+    disconnectedCallback() {
+        window.removeEventListener("scroll", this.scrollEventListener);
+        window.clearTimeout(this.scrollTimeout);
+    }
+    buildSectionTree(element, parent) {
+        for (const child of element.children) {
+            if (child.tagName === "TOBAGO-SECTION") {
+                const sectionNode = {
+                    id: child.id,
+                    title: this.getSectionTitle(child),
+                    level: parent ? parent.level + 1 : 0,
+                    children: []
+                };
+                parent.children.push(sectionNode);
+                this.buildSectionTree(child, sectionNode);
+            }
+            else {
+                this.buildSectionTree(child, parent);
+            }
+        }
+    }
+    getSectionTitle(section) {
+        const titleSpan = section.querySelector(".tobago-header span");
+        return titleSpan ? titleSpan.textContent.trim() : section.id;
+    }
+    renderTableOfContent(node, parent) {
+        parent.insertAdjacentHTML("afterbegin", `<a 
href="#${node.id}">${node.title}</a>`);

Review Comment:
   ## DOM text reinterpreted as HTML
   
   [DOM text](1) is reinterpreted as HTML without escaping meta-characters.
   
   [Show more 
details](https://github.com/apache/myfaces-tobago/security/code-scanning/67)



##########
tobago-example/tobago-example-demo/src/main/ts/demo-sidebar.ts:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+interface SectionNode {
+  id: string;
+  title: string;
+  level: number;
+  children: SectionNode[];
+}
+
+export class Sidebar extends HTMLElement {
+  private sectionTree: SectionNode;
+  private scrollThrottleTimeout?: number;
+  private scrollEventListener;
+  private scrollTimeout: number;
+
+  connectedCallback(): void {
+    if (this.fixedHeader) {
+      const resizeObserver = new ResizeObserver(() => {
+        const headerHeight = this.fixedHeader.offsetHeight;
+        const headerMarginBottom = 
parseFloat(getComputedStyle(this.fixedHeader).marginBottom);
+        this.rootHtml.style.scrollPaddingTop = headerHeight + 
headerMarginBottom + "px";
+        this.style.top = headerHeight + "px";
+      });
+      resizeObserver.observe(this.fixedHeader);
+    }
+    if (this.fixedFooter) {
+      const resizeObserver = new ResizeObserver(() => this.style.bottom = 
this.fixedFooter.offsetHeight + "px");
+      resizeObserver.observe(this.fixedFooter);
+    }
+
+    this.insertAdjacentHTML("afterbegin", "<strong>On this page</strong><nav 
id='tableOfContents'></nav>");
+
+    this.sectionTree = {
+      id: this.rootSection.id,
+      title: this.getSectionTitle(this.rootSection),
+      level: 0,
+      children: []
+    };
+    this.buildSectionTree(this.rootSection, this.sectionTree);
+    this.renderTableOfContent(this.sectionTree, this.tableOfContentsNav);
+    this.updateActiveNavLink();
+
+    this.scrollEventListener = this.scrollEvent.bind(this);
+    window.addEventListener("scroll", this.scrollEventListener);
+  }
+
+  disconnectedCallback(): void {
+    window.removeEventListener("scroll", this.scrollEventListener);
+    window.clearTimeout(this.scrollTimeout);
+  }
+
+  private buildSectionTree(element: HTMLElement, parent: SectionNode): void {
+    for (const child of element.children) {
+      if (child.tagName === "TOBAGO-SECTION") {
+        const sectionNode: SectionNode = {
+          id: child.id,
+          title: this.getSectionTitle(<HTMLElement>child),
+          level: parent ? parent.level + 1 : 0,
+          children: []
+        };
+        parent.children.push(sectionNode);
+        this.buildSectionTree(<HTMLElement>child, sectionNode);
+      } else {
+        this.buildSectionTree(<HTMLElement>child, parent);
+      }
+    }
+  }
+
+  private getSectionTitle(section: HTMLElement): string {
+    const titleSpan = section.querySelector(".tobago-header span");
+    return titleSpan ? titleSpan.textContent.trim() : section.id;
+  }
+
+  private renderTableOfContent(node: SectionNode, parent: HTMLElement): void {
+    parent.insertAdjacentHTML("afterbegin", `<a 
href="#${node.id}">${node.title}</a>`);

Review Comment:
   ## DOM text reinterpreted as HTML
   
   [DOM text](1) is reinterpreted as HTML without escaping meta-characters.
   
   [Show more 
details](https://github.com/apache/myfaces-tobago/security/code-scanning/66)



##########
tobago-example/tobago-example-demo/src/main/webapp/js/demo.js:
##########
@@ -332,6 +332,144 @@
         }
     });
 
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *      http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+    class Sidebar extends HTMLElement {
+        connectedCallback() {
+            if (this.fixedHeader) {
+                const resizeObserver = new ResizeObserver(() => {
+                    const headerHeight = this.fixedHeader.offsetHeight;
+                    const headerMarginBottom = 
parseFloat(getComputedStyle(this.fixedHeader).marginBottom);
+                    this.rootHtml.style.scrollPaddingTop = headerHeight + 
headerMarginBottom + "px";
+                    this.style.top = headerHeight + "px";
+                });
+                resizeObserver.observe(this.fixedHeader);
+            }
+            if (this.fixedFooter) {
+                const resizeObserver = new ResizeObserver(() => 
this.style.bottom = this.fixedFooter.offsetHeight + "px");
+                resizeObserver.observe(this.fixedFooter);
+            }
+            this.insertAdjacentHTML("afterbegin", "<strong>On this 
page</strong><nav id='tableOfContents'></nav>");
+            this.sectionTree = {
+                id: this.rootSection.id,
+                title: this.getSectionTitle(this.rootSection),
+                level: 0,
+                children: []
+            };
+            this.buildSectionTree(this.rootSection, this.sectionTree);
+            this.renderTableOfContent(this.sectionTree, 
this.tableOfContentsNav);
+            this.updateActiveNavLink();
+            this.scrollEventListener = this.scrollEvent.bind(this);
+            window.addEventListener("scroll", this.scrollEventListener);
+        }
+        disconnectedCallback() {
+            window.removeEventListener("scroll", this.scrollEventListener);
+            window.clearTimeout(this.scrollTimeout);
+        }
+        buildSectionTree(element, parent) {
+            for (const child of element.children) {
+                if (child.tagName === "TOBAGO-SECTION") {
+                    const sectionNode = {
+                        id: child.id,
+                        title: this.getSectionTitle(child),
+                        level: parent ? parent.level + 1 : 0,
+                        children: []
+                    };
+                    parent.children.push(sectionNode);
+                    this.buildSectionTree(child, sectionNode);
+                }
+                else {
+                    this.buildSectionTree(child, parent);
+                }
+            }
+        }
+        getSectionTitle(section) {
+            const titleSpan = section.querySelector(".tobago-header span");
+            return titleSpan ? titleSpan.textContent.trim() : section.id;
+        }
+        renderTableOfContent(node, parent) {
+            parent.insertAdjacentHTML("afterbegin", `<a 
href="#${node.id}">${node.title}</a>`);

Review Comment:
   ## DOM text reinterpreted as HTML
   
   [DOM text](1) is reinterpreted as HTML without escaping meta-characters.
   
   [Show more 
details](https://github.com/apache/myfaces-tobago/security/code-scanning/68)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@myfaces.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to