Skip to content

Commit 1a030a6

Browse files
committed
Enforce token auth for odic config PUT call
1 parent 7ef52d8 commit 1a030a6

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

backend/lib/express/jwt-decode.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ module.exports = () => {
44
return function (req, res, next) {
55
res.locals.access = null;
66
let access = new Access(res.locals.token || null);
7-
// allow unauthenticated access to OIDC configuration
8-
let anon_access = req.url === '/oidc-config' && !access.token.getUserId();
9-
access.load(anon_access)
7+
8+
// Allow unauthenticated access to get the oidc configuration
9+
let oidc_access =
10+
req.url === '/oidc-config' &&
11+
req.method === 'GET' &&
12+
!access.token.getUserId();
13+
14+
access.load(oidc_access)
1015
.then(() => {
1116
res.locals.access = access;
1217
next();

backend/routes/oidc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const crypto = require('crypto');
2-
const error = require('../../lib/error');
2+
const error = require('../lib/error');
33
const express = require('express');
4-
const jwtdecode = require('../../lib/express/jwt-decode');
5-
const logger = require('../../logger').oidc;
4+
const jwtdecode = require('../lib/express/jwt-decode');
5+
const logger = require('../logger').oidc;
66
const oidc = require('openid-client');
7-
const settingModel = require('../../models/setting');
8-
const internalToken = require('../../internal/token');
7+
const settingModel = require('../models/setting');
8+
const internalToken = require('../internal/token');
99

1010
let router = express.Router({
1111
caseSensitive: true,

backend/routes/settings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ router
7272
})
7373
.then((row) => {
7474
if (row.id === 'oidc-config') {
75-
// redact oidc configuration via api
75+
// Redact oidc configuration via api (unauthenticated get call)
7676
let m = row.meta;
7777
row.meta = {
7878
name: m.name,
7979
enabled: m.enabled === true && !!(m.clientID && m.clientSecret && m.issuerURL && m.redirectURL && m.name)
8080
};
81-
// remove these temporary cookies used during oidc authentication
81+
82+
// Remove these temporary cookies used during oidc authentication
8283
res.clearCookie('npm_oidc');
8384
res.clearCookie('npm_oidc_error');
8485
}

frontend/js/app/api.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ function fetch(verb, path, data, options) {
5959
},
6060

6161
beforeSend: function (xhr) {
62-
// allow unauthenticated access to OIDC configuration
63-
if (path === 'settings/oidc-config') return;
62+
// Allow unauthenticated access to get the oidc configuration
63+
if (path === 'settings/oidc-config' && verb === "get") {
64+
return;
65+
}
66+
6467
xhr.setRequestHeader('Authorization', 'Bearer ' + (token ? token.t : null));
6568
},
6669

0 commit comments

Comments
 (0)