Skip to content

Commit

Permalink
Portal: do not parse req body before proxying to caps servers
Browse files Browse the repository at this point in the history
Fixes an issue where request bodies were not available in cloud cap web servers. This was because they were already parsed in the portal server (reverse proxy for caps servers).
  • Loading branch information
chfritz committed Dec 12, 2024
1 parent a440bbe commit 3b053c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
49 changes: 25 additions & 24 deletions cloud/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cloud/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"express": "^4.17.1",
"express-openid-connect": "^2.17.1",
"express-session": "^1.17.2",
"http-proxy": "^1.18.1",
"http-proxy-node16": "^1.0.3",
"jest": "^28.1.0",
"json-logic-js": "^2.0.2",
"jsonwebtoken": "^8.5.1",
Expand Down
9 changes: 6 additions & 3 deletions cloud/app/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,14 @@ const app = express();

app.use(express.static(path.join(cwd, 'public')));
app.use(cors(), express.static(path.join(cwd, 'dist')));
app.use(express.json());

const capsRouter = express.Router();
app.use('/caps', capsRouter);

// Needs to come *after* capsRouter, to allow per-capability servers to parse
// the body when it arrives there.
app.use(express.json());

const addCapsRoutes = () => {
log.debug('adding caps router');
capsRouter.use(cookieParser());
Expand All @@ -255,7 +258,7 @@ const addCapsRoutes = () => {

/** Trades our token for a JWT with the permissions that were granted to
this token when it was created. */
capsRouter.post('/getJWTFromToken', async (req, res) => {
capsRouter.post('/getJWTFromToken', express.json(), async (req, res) => {
log.debug('tokenSession', req.session);

log.debug('get JWT from simple access token', req.body);
Expand Down Expand Up @@ -305,7 +308,7 @@ const addCapsRoutes = () => {
/** If the client already has a JWT, it can set it for the session here.
* This will authenticate him for capability routes who can just check the
* cookie. */
capsRouter.post('/setSessionJWT', async (req, res) => {
capsRouter.post('/setSessionJWT', express.json(), async (req, res) => {
log.debug('setting session JWT', req.body);
const {token} = req.body;
res.cookie(TOKEN_COOKIE, JSON.stringify({token}))
Expand Down

0 comments on commit 3b053c2

Please sign in to comment.