2 Commits
2.0 ... 2.1.1

Author SHA1 Message Date
Tommy Parnell
13f2ed4531 add missing quotes for unsafe-inline 2019-02-03 17:23:33 -05:00
Tommy Parnell
1f1c9ebd96 add upgrade insecure request 2019-02-03 13:40:54 -05:00
5 changed files with 12 additions and 5 deletions

View File

@@ -25,10 +25,11 @@ namespace HardHat.UnitTests
FormAction = new HashSet<string>() { "http://*.example.com" },
FrameAncestors = new HashSet<string>() { "http://*.example.com" },
PluginTypes = new HashSet<string>() { "http://*.example.com" },
Sandbox = SandboxOption.AllowPointerLock
Sandbox = SandboxOption.AllowPointerLock,
UpgradeInsecureRequests = true
});
Assert.Equal<string>(@"default-src 'self' 'none' http://*.example.com; script-src http://*.example.com; style-src http://*.example.com; img-src http://*.example.com; connect-src http://*.example.com; font-src http://*.example.com; object-src http://*.example.com; media-src http://*.example.com; child-src http://*.example.com; form-action http://*.example.com; frame-ancestors http://*.example.com; sandbox allow-pointer-lock; plugin-types http://*.example.com;", builder);
Assert.Equal<string>(@"default-src 'self' 'none' http://*.example.com; script-src http://*.example.com; style-src http://*.example.com; img-src http://*.example.com; connect-src http://*.example.com; font-src http://*.example.com; object-src http://*.example.com; media-src http://*.example.com; child-src http://*.example.com; form-action http://*.example.com; frame-ancestors http://*.example.com; sandbox allow-pointer-lock; plugin-types http://*.example.com; upgrade-insecure-requests;", builder);
}
[Fact]

View File

@@ -91,6 +91,10 @@ namespace HardHat.Builders
stringBuilder.Append(Constants.CSPDirectives.PluginTypes);
stringBuilder.Append($" {string.Join(" ", policy.PluginTypes)}; ");
}
if(policy.UpgradeInsecureRequests)
{
stringBuilder.Append($"{Constants.CSPDirectives.UpgradeInsecureRequests}; ");
}
return stringBuilder.ToString().TrimEnd();
}
}

View File

@@ -18,11 +18,11 @@ namespace HardHat
/// <summary>
/// Allows the use of inline resources, such as inline <script> elements, javascript: URLs, inline event handlers, and inline <style> elements. You must include the single quotes.
/// </summary>
public const string UnsafeInline = "unsafe-inline";
public const string UnsafeInline = "'unsafe-inline'";
/// <summary>
/// Allows the use of eval() and similar methods for creating code from strings. You must include the single quotes.
/// </summary>
public const string UnsafeEval = "unsafe-eval";
public const string UnsafeEval = "'unsafe-eval'";
/// <summary>
/// Refers to the empty set; that is, no URLs match. The single quotes are required.
/// </summary>
@@ -30,7 +30,7 @@ namespace HardHat
/// <summary>
/// The strict-dynamic source expression specifies that the trust explicitly given to a script present in the markup, by accompanying it with a nonce or a hash, shall be propagated to all the scripts loaded by that root script. At the same time, any whitelist or source expressions such as 'self' or 'unsafe-inline' will be ignored.
/// </summary>
public const string StrictDynamic = "strict-dynamic";
public const string StrictDynamic = "'strict-dynamic'";
/// <summary>
/// A whitelist for specific inline scripts using a cryptographic nonce (number used once). The server must generate a unique nonce value each time it transmits a policy. It is critical to provide an unguessable nonce, as bypassing a resources policy is otherwise trivial. See unsafe inline script for an example.
/// </summary>

View File

@@ -52,6 +52,7 @@
internal const string FormAction = "form-action";
internal const string FrameAncestors = "frame-ancestors";
internal const string PluginTypes = "plugin-types";
internal const string UpgradeInsecureRequests = "upgrade-insecure-requests";
}
}
}

View File

@@ -68,5 +68,6 @@ namespace HardHat
/// </summary>
public bool OnlySendReport { get; set; } = false;
public bool UpgradeInsecureRequests { get; set; } = false;
}
}