mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Prevent access to telemetry-properties route if the telemetry is disabled
This commit is contained in:
parent
8440d4064f
commit
9a2ae88480
@ -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();
|
||||
|
||||
|
||||
@ -3,4 +3,5 @@
|
||||
module.exports = {
|
||||
isAuthenticatedAdmin: require('./isAuthenticatedAdmin'),
|
||||
hasPermissions: require('./hasPermissions'),
|
||||
isTelemetryEnabled: require('./isTelemetryEnabled'),
|
||||
};
|
||||
|
||||
16
packages/core/admin/server/policies/isTelemetryEnabled.js
Normal file
16
packages/core/admin/server/policies/isTelemetryEnabled.js
Normal 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;
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -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',
|
||||
|
||||
@ -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');
|
||||
|
||||
|
||||
@ -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'));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user