Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new configuration property to allow unsafe redirect uris #191

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ const clients = [
oidc.initialize({ clients }).then(fulfillmentHandler, rejectionHandler);
```

If you use the "implicit" `grant_type` and the `application_type` "web" (default), then `redirect_uris` with the scheme
*http* or the host *localhost* are rejected by default. To enable unsafe `redirect_uris` you can set the configuration
property `allow_unsafe_redirect_uris` to true. **Do not activate this behavior in production!**

```js
const oidc = new Provider('http://localhost:3000');
const clients = [
{
allow_unsafe_redirect_uris: true, // Do not activate this behavior in production!
token_endpoint_auth_method: 'none',
client_id: 'mywebsite',
grant_types: ['implicit'],
response_types: ['id_token'],
redirect_uris: ['http://localhost/cb'],
},
{
// ...
},
];

oidc.initialize({ clients }).then(fulfillmentHandler, rejectionHandler);
```

**via Adapter**
Storing client metadata in your storage is recommended for distributed deployments. Also when you
want to provide a client configuration GUI or plan on changing this data often. Clients get loaded
Expand Down
2 changes: 2 additions & 0 deletions lib/consts/client_attributes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const RECOGNIZED_METADATA = [
'allow_unsafe_redirect_uris',
'application_type',
'client_id_issued_at',
'client_id',
Expand Down Expand Up @@ -28,6 +29,7 @@ const RECOGNIZED_METADATA = [
];

const DEFAULT = {
allow_unsafe_redirect_uris: false,
application_type: 'web',
grant_types: ['authorization_code'],
id_token_signed_response_alg: 'RS256',
Expand Down
14 changes: 8 additions & 6 deletions lib/helpers/client_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,16 @@ module.exports = function getSchema(provider) {

switch (this.application_type) { // eslint-disable-line default-case
case 'web': {
const { hostname, protocol } = parseRedirectUri(redirectUri);
if (this.allow_unsafe_redirect_uris !== true) {
const { hostname, protocol } = parseRedirectUri(redirectUri);

if (this.grant_types.includes('implicit') && protocol === 'http:') {
invalidate('redirect_uris for web clients using implicit flow MUST only register URLs using the https scheme');
}
if (this.grant_types.includes('implicit') && protocol === 'http:') {
invalidate('redirect_uris for web clients using implicit flow MUST only register URLs using the https scheme');
}

if (this.grant_types.includes('implicit') && hostname === 'localhost') {
invalidate('redirect_uris for web clients using implicit flow must not be using localhost');
if (this.grant_types.includes('implicit') && hostname === 'localhost') {
invalidate('redirect_uris for web clients using implicit flow must not be using localhost');
}
}
break;
}
Expand Down
12 changes: 12 additions & 0 deletions test/configuration/client_metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ describe('Client metadata validation', () => {
grant_types: ['implicit', 'authorization_code'],
response_types: ['code id_token'],
});
allows(this.title, ['https://localhost'], undefined, {
allow_unsafe_redirect_uris: true,
application_type: 'web',
grant_types: ['implicit', 'authorization_code'],
response_types: ['code id_token'],
});
allows(this.title, ['http://localhost'], undefined, {
application_type: 'web',
});
Expand Down Expand Up @@ -348,6 +354,12 @@ describe('Client metadata validation', () => {
grant_types: ['implicit'],
response_types: ['id_token'],
});
allows(this.title, ['http://foo/bar'], undefined, {
allow_unsafe_redirect_uris: true,
application_type: 'web',
grant_types: ['implicit'],
response_types: ['id_token'],
});
});

context('request_object_signing_alg', function () {
Expand Down