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

Enable session middleware by default (fixes U&P provider authentication) #11825

Merged
merged 16 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/actions/run-e2e-tests/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ if [[ -z "$RUN_EE" ]]; then
export STRAPI_DISABLE_EE=true
fi

export ENV_PATH="$(pwd)/testApp/.env"

echo "env path :"
echo $ENV_PATH

opts=($DB_OPTIONS)

yarn run -s test:generate-app "${opts[@]}" $@
Expand Down
1 change: 1 addition & 0 deletions examples/getstarted/config/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = [
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
// 'strapi::compression',
// 'strapi::ip',
{
Expand Down
4 changes: 4 additions & 0 deletions examples/getstarted/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ const cronTasks = require('./src/cron-tasks');
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'http://localhost:1337',
cron: {
enabled: true,
tasks: cronTasks,
},
app: {
keys: env.array('APP_SECRETS', ['toBeModified1', 'toBeModified2']),
},
});
3 changes: 0 additions & 3 deletions packages/core/admin/server/strategies/api-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ const extractToken = ctx => {

return parts[1];
}
if (ctx.query.access_token) {
return ctx.query.access_token;
}

return null;
};
Expand Down
10 changes: 4 additions & 6 deletions packages/core/strapi/lib/Strapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,13 @@ class Strapi {
}

sendStartupTelemetry() {
// Get database clients
const databaseClients = _.map(this.config.get('connections'), _.property('settings.client'));

// Emit started event.
// do not await to avoid slower startup
this.telemetry.send('didStartServer', {
database: databaseClients,
plugins: this.config.installedPlugins,
providers: this.config.installedProviders,
database: strapi.config.get('database.connection.client'),
plugins: Object.keys(strapi.plugins),
// TODO: to add back
// providers: this.config.installedProviders,
petersg83 marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/strapi/lib/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const query = require('./query');
const responseTime = require('./response-time');
const responses = require('./responses');
const security = require('./security');
// TODO: add back ?
// session: require('./session'),
const session = require('./session');
const publicStatic = require('./public');

module.exports = {
Expand All @@ -23,6 +22,7 @@ module.exports = {
cors,
responseTime,
poweredBy,
session,
logger,
compression,
responses,
Expand Down
28 changes: 28 additions & 0 deletions packages/core/strapi/lib/middlewares/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const { defaultsDeep, isEmpty, isArray } = require('lodash/fp');
const session = require('koa-session');

const defaultConfig = {
petersg83 marked this conversation as resolved.
Show resolved Hide resolved
key: 'koa.sess',
maxAge: 86400000,
autoCommit: true,
overwrite: true,
httpOnly: true,
signed: true,
rolling: false,
renew: false,
secure: process.env.NODE_ENV === 'production' ? true : false,
sameSite: null,
};

module.exports = (userConfig, { strapi }) => {
const keys = strapi.server.app.keys;
if (!isArray(keys) || isEmpty(keys) || keys.some(isEmpty)) {
throw new Error(`App keys are required. Please set app.keys in config/server.js (ex: keys: ['myKeyA', 'myKeyB'])`);
}

const config = defaultsDeep(defaultConfig, userConfig);

strapi.server.use(session(config, strapi.server.app));
};

This file was deleted.

18 changes: 0 additions & 18 deletions packages/core/strapi/lib/middlewares/session/defaults.json

This file was deleted.

140 changes: 0 additions & 140 deletions packages/core/strapi/lib/middlewares/session/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/strapi/lib/services/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = strapi => {

const normalizedPath = path.normalize(filePath).replace(/^\/?(\.\/|\.\.\/)+/, '');

return path.join(strapi.dirs.root, normalizedPath);
return path.resolve(strapi.dirs.root, normalizedPath);
}

const strapiFS = {
Expand Down
5 changes: 4 additions & 1 deletion packages/core/strapi/lib/services/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ const healthCheck = async ctx => {
* @returns {Server}
*/
const createServer = strapi => {
const app = createKoaApp({ proxy: strapi.config.get('server.proxy') });
const app = createKoaApp({
proxy: strapi.config.get('server.proxy'),
keys: strapi.config.get('server.app.keys'),
});

const router = new Router();

Expand Down
3 changes: 2 additions & 1 deletion packages/core/strapi/lib/services/server/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ const addCustomMethods = app => {
return app;
};

const createKoaApp = ({ proxy }) => {
const createKoaApp = ({ proxy, keys }) => {
const app = new Koa({ proxy });
app.keys = keys;

addCustomMethods(app);

Expand Down