Prevent access to telemetry-properties route if the telemetry is disabled

This commit is contained in:
Convly 2022-04-13 16:11:42 +02:00
parent 8440d4064f
commit 9a2ae88480
6 changed files with 35 additions and 16 deletions

View File

@ -68,23 +68,19 @@ function App() {
useEffect(() => {
const getData = async () => {
try {
const [
{
data: {
data: { hasAdmin, uuid },
},
const {
data: {
data: { hasAdmin, uuid },
},
{
data: { data: properties },
},
] = await Promise.all([
axios.get(`${strapi.backendURL}/admin/init`),
axios.get(`${strapi.backendURL}/admin/telemetry-properties`),
]);
setTelemetryProperties(properties);
} = await axios.get(`${strapi.backendURL}/admin/init`);
if (uuid) {
const {
data: { data: properties },
} = await axios.get(`${strapi.backendURL}/admin/telemetry-properties`);
setTelemetryProperties(properties);
try {
const deviceId = await getUID();

View File

@ -3,4 +3,5 @@
module.exports = {
isAuthenticatedAdmin: require('./isAuthenticatedAdmin'),
hasPermissions: require('./hasPermissions'),
isTelemetryEnabled: require('./isTelemetryEnabled'),
};

View File

@ -0,0 +1,16 @@
'use strict';
const { createPolicy } = require('@strapi/utils').policy;
/**
* This policy is used for routes dealing with telemetry and analytics content.
* It will fails when the telemetry has been disabled on the server.
*/
module.exports = createPolicy({
name: 'admin::isTelemetryEnabled',
handler(_ctx, _config, { strapi }) {
if (strapi.telemetry.isDisabled) {
return false;
}
},
});

View File

@ -25,7 +25,10 @@ module.exports = [
method: 'GET',
path: '/telemetry-properties',
handler: 'admin.telemetryProperties',
config: { auth: false },
config: {
auth: false,
policies: ['admin::isTelemetryEnabled'],
},
},
{
method: 'GET',

View File

@ -6,7 +6,6 @@ const { isFunction } = require('lodash/fp');
const { createLogger } = require('@strapi/logger');
const { Database } = require('@strapi/database');
const { createAsyncParallelHook } = require('@strapi/utils').hooks;
const { isTypeScriptProjectSync } = require('@strapi/typescript-utils');
const loadConfiguration = require('./core/app-configuration');

View File

@ -31,6 +31,10 @@ const createTelemetryInstance = strapi => {
const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });
return {
get isDisabled() {
return isDisabled;
},
register() {
if (!isDisabled) {
const pingCron = scheduleJob('0 0 12 * * *', () => sendEvent('ping'));