|
@@ -11,6 +11,8 @@ import (
|
|
|
|
|
|
This is a permission policy header modifier that changes
|
|
|
the request permission related policy fields
|
|
|
+
|
|
|
+ author: tobychui
|
|
|
*/
|
|
|
|
|
|
type PermissionsPolicy struct {
|
|
@@ -58,6 +60,54 @@ type PermissionsPolicy struct {
|
|
|
VerticalScroll []string `json:"vertical_scroll"`
|
|
|
}
|
|
|
|
|
|
+// GetDefaultPermissionPolicy returns a PermissionsPolicy struct with all policies set to *
|
|
|
+func GetDefaultPermissionPolicy() *PermissionsPolicy {
|
|
|
+ return &PermissionsPolicy{
|
|
|
+ Accelerometer: []string{"*"},
|
|
|
+ AmbientLightSensor: []string{"*"},
|
|
|
+ Autoplay: []string{"*"},
|
|
|
+ Battery: []string{"*"},
|
|
|
+ Camera: []string{"*"},
|
|
|
+ CrossOriginIsolated: []string{"*"},
|
|
|
+ DisplayCapture: []string{"*"},
|
|
|
+ DocumentDomain: []string{"*"},
|
|
|
+ EncryptedMedia: []string{"*"},
|
|
|
+ ExecutionWhileNotRendered: []string{"*"},
|
|
|
+ ExecutionWhileOutOfView: []string{"*"},
|
|
|
+ Fullscreen: []string{"*"},
|
|
|
+ Geolocation: []string{"*"},
|
|
|
+ Gyroscope: []string{"*"},
|
|
|
+ KeyboardMap: []string{"*"},
|
|
|
+ Magnetometer: []string{"*"},
|
|
|
+ Microphone: []string{"*"},
|
|
|
+ Midi: []string{"*"},
|
|
|
+ NavigationOverride: []string{"*"},
|
|
|
+ Payment: []string{"*"},
|
|
|
+ PictureInPicture: []string{"*"},
|
|
|
+ PublicKeyCredentialsGet: []string{"*"},
|
|
|
+ ScreenWakeLock: []string{"*"},
|
|
|
+ SyncXHR: []string{"*"},
|
|
|
+ USB: []string{"*"},
|
|
|
+ WebShare: []string{"*"},
|
|
|
+ XRSpatialTracking: []string{"*"},
|
|
|
+ ClipboardRead: []string{"*"},
|
|
|
+ ClipboardWrite: []string{"*"},
|
|
|
+ Gamepad: []string{"*"},
|
|
|
+ SpeakerSelection: []string{"*"},
|
|
|
+ ConversionMeasurement: []string{"*"},
|
|
|
+ FocusWithoutUserActivation: []string{"*"},
|
|
|
+ HID: []string{"*"},
|
|
|
+ IdleDetection: []string{"*"},
|
|
|
+ InterestCohort: []string{"*"},
|
|
|
+ Serial: []string{"*"},
|
|
|
+ SyncScript: []string{"*"},
|
|
|
+ TrustTokenRedemption: []string{"*"},
|
|
|
+ Unload: []string{"*"},
|
|
|
+ WindowPlacement: []string{"*"},
|
|
|
+ VerticalScroll: []string{"*"},
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// InjectPermissionPolicyHeader inject the permission policy into headers
|
|
|
func InjectPermissionPolicyHeader(w http.ResponseWriter, policy *PermissionsPolicy) {
|
|
|
//Keep the original Permission Policy if exists, or there are no policy given
|
|
@@ -71,11 +121,23 @@ func InjectPermissionPolicyHeader(w http.ResponseWriter, policy *PermissionsPoli
|
|
|
addDirective := func(name string, sources []string) {
|
|
|
if len(sources) > 0 {
|
|
|
if sources[0] == "*" {
|
|
|
+ //Allow all
|
|
|
policyHeader = append(policyHeader, fmt.Sprintf("%s=%s", name, "*"))
|
|
|
} else {
|
|
|
- policyHeader = append(policyHeader, fmt.Sprintf("%s=(%s)", name, strings.Join(sources, ", ")))
|
|
|
+ //Other than "self" which do not need double quote, others domain need double quote in place
|
|
|
+ formatedSources := []string{}
|
|
|
+ for _, source := range sources {
|
|
|
+ if source == "self" {
|
|
|
+ formatedSources = append(formatedSources, "self")
|
|
|
+ } else {
|
|
|
+ formatedSources = append(formatedSources, "\""+source+"\"")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ policyHeader = append(policyHeader, fmt.Sprintf("%s=(%s)", name, strings.Join(formatedSources, " ")))
|
|
|
}
|
|
|
-
|
|
|
+ } else {
|
|
|
+ //There are no setting for this field. Assume no permission
|
|
|
+ policyHeader = append(policyHeader, fmt.Sprintf("%s=()", name))
|
|
|
}
|
|
|
}
|
|
|
|