Skip to content

Commit

Permalink
feat(application-config): add permissions policy header (#2143)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeekens authored Apr 14, 2021
1 parent ed7f6ac commit 53b27b0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .changeset/bright-glasses-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@commercetools-frontend/application-config": minor
"@commercetools-frontend/mc-html-template": minor
"@commercetools-frontend/mc-scripts": minor
"@commercetools-website/custom-applications": minor
---

Adds support for specifying the `Permissions-Policy` header supported in Chrome 90.

Similar to the `Feature-Policies` header an application config now support a `permissionsPolicies` field.

```js
headers: {
permissionPolicies: {
mircophone: '()'
}
}
```

More information about supported permission policies can be found [here](https://github.com/w3c/webappsec-permissions-policy/blob/main/permissions-policy-explainer.md).
4 changes: 4 additions & 0 deletions packages/application-config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
"featurePolicies": {
"description": "Configuration for the HTTP Feature-Policy header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Feature_Policy/Using_Feature_Policy)",
"type": "object"
},
"permissionsPolicies": {
"description": "Configuration for the HTTP Permissions-Policy header (https://github.com/w3c/webappsec-permissions-policy/blob/main/permissions-policy-explainer.md)",
"type": "object"
}
},
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions packages/application-config/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,11 @@ export interface JSONSchemaForCustomApplicationConfigurationFiles {
featurePolicies?: {
[k: string]: unknown;
};
/**
* Configuration for the HTTP Permissions-Policy header (https://github.com/w3c/webappsec-permissions-policy/blob/main/permissions-policy-explainer.md)
*/
permissionsPolicies?: {
[k: string]: unknown;
};
};
}
5 changes: 4 additions & 1 deletion packages/application-config/test/fixtures/config-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
},
"featurePolicies": {
"microphone": "none"
},
"permissionsPolicies": {
"microphone": "()"
}
}
}
}
12 changes: 12 additions & 0 deletions packages/application-config/test/process-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ describe('processing a full config', () => {
featurePolicies: {
microphone: 'none',
},
permissionsPolicies: {
microphone: '()',
},
},
});
});
Expand Down Expand Up @@ -229,6 +232,9 @@ describe('processing a full config', () => {
featurePolicies: {
microphone: 'none',
},
permissionsPolicies: {
microphone: '()',
},
},
});
});
Expand Down Expand Up @@ -269,6 +275,9 @@ describe('processing a full config', () => {
featurePolicies: {
microphone: 'none',
},
permissionsPolicies: {
microphone: '()',
},
},
});
});
Expand Down Expand Up @@ -314,6 +323,9 @@ describe('processing a full config', () => {
featurePolicies: {
microphone: 'none',
},
permissionsPolicies: {
microphone: '()',
},
},
});
});
Expand Down
5 changes: 5 additions & 0 deletions packages/mc-html-template/src/process-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ const processHeaders = (applicationConfig) => {
applicationConfig.headers.featurePolicies
),
}),
...(applicationConfig.headers.permissionsPolicies && {
'Permissions-Policy': toHeaderString(
applicationConfig.headers.permissionsPolicies
),
}),
};
};

Expand Down
1 change: 0 additions & 1 deletion packages/mc-scripts/src/compile-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
const publicAssetsPath = resolveApp('public');

const paths = {
featurePoliciesPath: flags.featurePolicies,
publicAssetsPath,
// NOTE: previously, for running the prod server locally, we were copying
// assets into public/assets and compiling the index.html into public folder.
Expand Down
4 changes: 4 additions & 0 deletions website/src/content/development/application-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ The `csp` object can be used to define additional settings for the following dir

The `featurePolicies` object can be used to configure the [HTTP `Feature-Policy` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Feature_Policy/Using_Feature_Policy).

### `headers.permissionsPolicies`

The `permissionsPolicies` object can be used to configure the [HTTP `Permission-Policy` header](https://github.com/w3c/webappsec-permissions-policy/blob/main/permissions-policy-explainer.md).

## JSON Schema support for VSCode

To enable JSON schema autocompletion and validation support, add a reference to the `schema.json` URL in the VSCode settings (either user settings or workspace settings):
Expand Down

1 comment on commit 53b27b0

@vercel
Copy link

@vercel vercel bot commented on 53b27b0 Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.