Skip to content

[Code scan] Inject banner body markup outside <head> #82

Description

@njzjz

This issue is a result of a Codex global code scan of deepmodeling/deepmodeling_sphinx at commit 156679f.

Problem

insert_sidebar() injects the fully rendered banner immediately before </head>, but banner.html contains visible body markup such as <div class="container-fluid header-holder ..."> and the mobile menu. This produces invalid HTML where body content is placed inside the document head.

Code references:

begin_body = content.lower().find("</head>")
banner = render_banner(current_site=app.config.deepmodeling_current_site)
if begin_body != -1:
content = (
content[:begin_body]
+ comment_begin
+ banner
+ comment_end
+ content[begin_body:]

<link rel="preconnect" href="https://unpkg.com/" />
<link
rel="icon"
href="https://unpkg.com/@njzjz/icons@0.0.5/logos/deepmodeling.svg"
type="image/png"
/>

<div class="container-fluid header-holder tutorials-header" id="header-holder">
<div class="container">
<div class="header-container">
<a
class="header-logo"
href="https://deepmodeling.com"
aria-label="deepmodeling"
></a>
<div class="main-menu">
<ul>
{% for item in items %}
<li class="{{ item.class }}">
{% if item.subitem %}
<div
id="resourcesDropdownButton"
data-toggle="resources-dropdown"
class="resources-dropdown"
>
<a
href="{{ item.url }}"
class="resource-option with-down-orange-arrow"
>
{{ item.title }}
</a>
<div class="resources-dropdown-menu">
{% for subitem in item.subitem %}
<a
class="doc-dropdown-option nav-dropdown-item"
href="{{ subitem.url }}"
>
<span class="dropdown-title">{{ subitem.title }}</span>
<p></p>
</a>
{% endfor %}
</div>
</div>
{% else %}
<a href="{{ item.url }}">{{ item.title }}</a>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
<a
class="main-menu-open-button"
href="#"
data-behavior="open-mobile-menu"
></a>
</div>
</div>
</div>
<div class="mobile-main-menu">
<div class="container-fluid">
<div class="container">
<div class="mobile-main-menu-header-container">
<a
class="header-logo"
href="https://deepmodeling.com"
aria-label="deepmodeling"
></a>
<a
class="main-menu-close-button"
href="#"
data-behavior="close-mobile-menu"
></a>
</div>
</div>
</div>
<div class="mobile-main-menu-links-container">
<div class="main-menu">
<ul>
{% for item in items %}
<li>
<a href="{{ item.url }}">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>

Impact

Browsers may recover by implicitly closing <head>, but the output is invalid and can interact poorly with themes, crawlers, validators, and scripts that assume a normal head/body structure. In a minimal Sphinx HTML build, the generated page contains the banner <div> before </head><body>.

Suggested fix

Split head-only tags from visible banner markup, or inject the visible banner immediately after the opening <body> tag while keeping preconnect/favicon tags in <head>. While touching the head tags, the SVG favicon should also use type="image/svg+xml" instead of type="image/png".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions