Skip to content

Commit

Permalink
Merge pull request #1 from dnanexus/fix/security-scan
Browse files Browse the repository at this point in the history
Fix/security scan
  • Loading branch information
agesto-dna authored Jul 10, 2024
2 parents 96a7465 + d397582 commit cdb8cf9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"express": "^4.19.2",
"express-session": "^1.18.0",
"jose": "^5.6.2",
"openid-client": "^5.6.5"
"lusca": "^1.7.0",
"openid-client": "^5.6.5"
}
}
10 changes: 8 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
const express = require('express');
const session = require('express-session');
const { csrf } = require('lusca');
const { randomUUID } = require('crypto');
const { URL } = require('url');
const bodyParser = require('body-parser');
const config = require('./config/config');
const routes = require('./routes');
const errorHandler = require('./errorHandler');
const { randomUUID } = require('crypto');

const callbackProtocol = new URL(config.oidc.redirect_url).protocol;

const app = express();

app.use(session({
secret: randomUUID(),
cookie: { maxAge: 60000, secure: callbackProtocol === 'https:'},
resave: false,
saveUninitialized: true
}));

app.use(bodyParser.urlencoded({ extended: true }));
app.use(csrf());

app.use('/', routes);
app.use(errorHandler);


app.listen(config.port, () => {
console.log(`App listening at http://localhost:${config.port}`);
});
Expand Down
7 changes: 4 additions & 3 deletions src/controllers/homeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const config = require('../config/config');

function home (req, res) {
const scopes = config.oidc.scopes.split(' ');

const scopeCheckboxes = scopes.map(scope =>
`<label>
<input type="checkbox" name="scope" value="${scope}">${scope}
Expand All @@ -11,10 +11,11 @@ function home (req, res) {

res.send (
`<h1>Welcome</h1>
<form action="/login" method="post">
<form action="/login" method="post">
<p>Select scopes for the authentication:</p>
${scopeCheckboxes}
${scopeCheckboxes}
<p>
<input type="hidden" name="_csrf" value="${req.csrfToken()}">
<button type="submit">Log in with DNAnexus</button>
</p>
</form>`);
Expand Down

0 comments on commit cdb8cf9

Please sign in to comment.