Commit cdab7938 authored by Chris Müller's avatar Chris Müller Committed by Richard Haeser

[BUGFIX] Prevent indexing of XML sitemaps by search engines

The content of a XML sitemap should not be listed on search engine result
pages. This patch adds the HTTP header "X-Robots-Tag:noindex" to the
XML sitemaps.

Resolves: #89617
Releases: master, 9.5
Change-Id: I307b15ebcb26973846edc17f9b46562c1d38db45
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62253Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarKevin Appelt <kevin.appelt@icloud.com>
Tested-by: default avatarRichard Haeser <richard@maxserv.com>
Reviewed-by: default avatarTymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: default avatarKevin Appelt <kevin.appelt@icloud.com>
Reviewed-by: default avatarRichard Haeser <richard@maxserv.com>
parent ddaeb563
......@@ -9,8 +9,9 @@ seo_sitemap {
removeDefaultJS = 1
removeDefaultCss = 1
removePageCss = 1
additionalHeaders.10 {
header = Content-Type:application/xml;charset=utf-8
additionalHeaders {
10.header = Content-Type:application/xml;charset=utf-8
20.header = X-Robots-Tag:noindex
}
}
......
......@@ -67,6 +67,10 @@ class XmlSitemapIndexTest extends AbstractTestCase
self::assertEquals(200, $response->getStatusCode());
self::assertArrayHasKey('Content-Length', $response->getHeaders());
self::assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
self::assertArrayHasKey('Content-Type', $response->getHeaders());
self::assertEquals('application/xml;charset=utf-8', $response->getHeader('Content-Type')[0]);
self::assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
self::assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);
self::assertRegExp('/<loc>http:\/\/localhost\/\?sitemap=pages&amp;type=1533906435&amp;cHash=[^<]+<\/loc>/', (string)$response->getBody());
}
}
......@@ -81,6 +81,10 @@ class XmlSitemapPagesTest extends AbstractTestCase
self::assertEquals(200, $this->response->getStatusCode());
self::assertArrayHasKey('Content-Length', $this->response->getHeaders());
self::assertGreaterThan(0, $this->response->getHeader('Content-Length')[0]);
self::assertArrayHasKey('Content-Type', $this->response->getHeaders());
self::assertEquals('application/xml;charset=utf-8', $this->response->getHeader('Content-Type')[0]);
self::assertArrayHasKey('X-Robots-Tag', $this->response->getHeaders());
self::assertEquals('noindex', $this->response->getHeader('X-Robots-Tag')[0]);
self::assertRegExp($urlPattern, (string)$this->response->getBody());
}
......
......@@ -80,6 +80,10 @@ class XmlSitemapRecordsTest extends AbstractTestCase
);
self::assertEquals(200, $response->getStatusCode());
self::assertArrayHasKey('Content-Type', $response->getHeaders());
self::assertEquals('application/xml;charset=utf-8', $response->getHeader('Content-Type')[0]);
self::assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
self::assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);
self::assertArrayHasKey('Content-Length', $response->getHeaders());
$stream = $response->getBody();
$stream->rewind();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment