-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample8.php
More file actions
32 lines (30 loc) · 1.24 KB
/
Copy pathexample8.php
File metadata and controls
32 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require_once('../CSPGenerator.php');
// Automatically rewrite http:// url's to https:// url's when using https(HTTP over TLS/SSL).
CSPGenerator::getInstance()->setUpgradeInsecureRequests(true);
CSPGenerator::getInstance()->addImagesrc('upload.wikimedia.org');
// Set the headers, always call this method before any content output.
CSPGenerator::getInstance()->Parse();
// Start content output.
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>example8 - Upgrade-insecure-requests</title>
</head>
<body>
<?php
$ishttps = false;
if (isset($_SERVER['HTTPS'])) {
if ($_SERVER['HTTPS'] == 'on') {
$ishttps = true;
}
}
if ($ishttps) { ?>
Image source url starts with http:// protocol handler but it's rewriten to the https:// protocol handler to load the image with https because of the <code>upgrade-insecure-requests</code> directive in the Content Security Policy header.<br />
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Internet2.jpg/320px-Internet2.jpg" alt="Image with http url will be loaded as https url.">
<?php } else { ?>
<b>To test the Content Security Policy <code>Upgrade-insecure-requests</code> directive it's required to visit this page over https.</b>
<?php } ?>
</body>
</html>