added objectHasProperty to ifs in security files
MODIFY
src/server/rest/v1/service/security/AssetSecurity.ts
src/server/rest/v1/service/security/AssetSecurity.ts
import { HttpAssetConsumptionRequest, HttpAssetImageRequest, HttpAssetRequest, HttpAssetsRequest } from '../../../../../types/requests/HttpAssetRequest';
import Asset from '../../../../../types/Asset';
+import Utils from '../../../../../utils/Utils';
import UtilsSecurity from './UtilsSecurity';
import sanitize from 'mongo-sanitize';
@@ -68,13 +69,13 @@ export default class AssetSecurity {
filteredRequest.staticValueWatt = sanitize(request.staticValueWatt),
filteredRequest.image = request.image;
filteredRequest.dynamicAsset = UtilsSecurity.filterBoolean(request.dynamicAsset);
- if (request.coordinates && request.coordinates.length === 2) {
+ if (Utils.objectHasProperty(request, 'coordinates') && request.coordinates.length === 2) {
filteredRequest.coordinates = [
sanitize(request.coordinates[0]),
sanitize(request.coordinates[1])
];
}
- if (request.dynamicAsset) {
+ if (Utils.objectHasProperty(request, 'dynamicAsset')) {
filteredRequest.connectionID = sanitize(request.connectionID);
filteredRequest.meterID = sanitize(request.meterID);
}

MODIFY
src/server/rest/v1/service/security/BillingSecurity.ts
src/server/rest/v1/service/security/BillingSecurity.ts
@@ -2,16 +2,17 @@ import { HttpCreateTransactionInvoiceRequest, HttpForceSynchronizeUserInvoicesRe
import { HttpBillingInvoiceRequest } from '../../../../../types/requests/HttpBillingRequest';
import HttpByIDRequest from '../../../../../types/requests/HttpByIDRequest';
+import Utils from '../../../../../utils/Utils';
import UtilsSecurity from './UtilsSecurity';
import sanitize from 'mongo-sanitize';
export default class BillingSecurity {
static filterSynchronizeUserRequest(request: any): HttpSynchronizeUserRequest {
const filteredUser: HttpSynchronizeUserRequest = {} as HttpSynchronizeUserRequest;
- if (request.id) {
+ if (Utils.objectHasProperty(request, 'id')) {
filteredUser.id = sanitize(request.id);
}
- if (request.email) {
+ if (Utils.objectHasProperty(request, 'email')) {
filteredUser.email = sanitize(request.email);
}
return filteredUser;
@@ -19,19 +20,19 @@ export default class BillingSecurity {
static filterGetUserInvoicesRequest(request: any): HttpBillingInvoiceRequest {
const filteredRequest = {} as HttpBillingInvoiceRequest;
- if (request.UserID) {
+ if (Utils.objectHasProperty(request, 'UserID')) {
filteredRequest.UserID = sanitize(request.UserID);
}
- if (request.Status) {
+ if (Utils.objectHasProperty(request, 'Status')) {
filteredRequest.Status = sanitize(request.Status);
}
- if (request.StartDateTime) {
+ if (Utils.objectHasProperty(request, 'StartDateTime')) {
filteredRequest.StartDateTime = sanitize(request.StartDateTime);
}
- if (request.EndDateTime) {
+ if (Utils.objectHasProperty(request, 'EndDateTime')) {
filteredRequest.EndDateTime = sanitize(request.EndDateTime);
}
- if (request.Search) {
+ if (Utils.objectHasProperty(request, 'Search')) {
filteredRequest.Search = sanitize(request.Search);
}
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);

MODIFY
src/server/rest/v1/service/security/ChargingStationSecurity.ts
src/server/rest/v1/service/security/ChargingStationSecurity.ts
@@ -2,7 +2,6 @@ import { ChargingProfile, ChargingSchedule, ChargingSchedulePeriod, Profile } fr
import { HttpChargingProfilesRequest, HttpChargingStationCommandRequest, HttpChargingStationConnectorRequest, HttpChargingStationGetFirmwareRequest, HttpChargingStationLimitPowerRequest, HttpChargingStationOcppParametersRequest, HttpChargingStationOcppRequest, HttpChargingStationParamsUpdateRequest, HttpChargingStationRequest, HttpChargingStationSetMaxIntensitySocketRequest, HttpChargingStationsRequest, HttpDownloadQrCodeRequest, HttpIsAuthorizedRequest, HttpTriggerSmartChargingRequest } from '../../../../../types/requests/HttpChargingStationRequest';
import { Command } from '../../../../../types/ChargingStation';
-import HttpByIDRequest from '../../../../../types/requests/HttpByIDRequest';
import HttpDatabaseRequest from '../../../../../types/requests/HttpDatabaseRequest';
import Utils from '../../../../../utils/Utils';
import UtilsSecurity from './UtilsSecurity';
@@ -84,7 +83,7 @@ export default class ChargingStationSecurity {
public static filterChargingStationsRequest(request: any): HttpChargingStationsRequest {
const filteredRequest = {} as HttpChargingStationsRequest;
- if (request.Issuer) {
+ if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
filteredRequest.Search = sanitize(request.Search);
@@ -102,7 +101,7 @@ export default class ChargingStationSecurity {
Utils.convertToFloat(sanitize(request.LocLongitude)),
Utils.convertToFloat(sanitize(request.LocLatitude))
];
- if (request.LocMaxDistanceMeters) {
+ if (Utils.objectHasProperty(request, 'LocMaxDistanceMeters')) {
request.LocMaxDistanceMeters = Utils.convertToInt(sanitize(request.LocMaxDistanceMeters));
if (request.LocMaxDistanceMeters > 0) {
filteredRequest.LocMaxDistanceMeters = request.LocMaxDistanceMeters;
@@ -143,14 +142,14 @@ export default class ChargingStationSecurity {
if (Utils.objectHasProperty(request, 'siteAreaID')) {
filteredRequest.siteAreaID = sanitize(request.siteAreaID);
}
- if (request.coordinates && request.coordinates.length === 2) {
+ if (Utils.objectHasProperty(request, 'coordinates') && request.coordinates.length === 2) {
filteredRequest.coordinates = [
sanitize(request.coordinates[0]),
sanitize(request.coordinates[1])
];
}
// Filter connectors
- if (request.connectors) {
+ if (Utils.objectHasProperty(request, 'connectors')) {
filteredRequest.connectors = request.connectors.map((connector) => {
if (connector) {
return {
@@ -198,7 +197,7 @@ export default class ChargingStationSecurity {
filteredRequest.carID = sanitize(request.carID);
}
// Do not check action?
- if (request.args) {
+ if (Utils.objectHasProperty(request, 'args')) {
filteredRequest.args = {};
// Check
if (Utils.objectHasProperty(request.args, 'type')) {

MODIFY
src/server/rest/v1/service/security/CompanySecurity.ts
src/server/rest/v1/service/security/CompanySecurity.ts
@@ -31,7 +31,7 @@ export default class CompanySecurity {
WithSites: UtilsSecurity.filterBoolean(request.WithSites),
WithLogo: UtilsSecurity.filterBoolean(request.WithLogo)
} as HttpCompaniesRequest;
- if (request.Issuer) {
+ if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
if (Utils.containsGPSCoordinates([request.LocLongitude, request.LocLatitude])) {
@@ -39,7 +39,7 @@ export default class CompanySecurity {
Utils.convertToFloat(sanitize(request.LocLongitude)),
Utils.convertToFloat(sanitize(request.LocLatitude))
];
- if (request.LocMaxDistanceMeters) {
+ if (Utils.objectHasProperty(request, 'LocMaxDistanceMeters')) {
request.LocMaxDistanceMeters = Utils.convertToInt(sanitize(request.LocMaxDistanceMeters));
if (request.LocMaxDistanceMeters > 0) {
filteredRequest.LocMaxDistanceMeters = request.LocMaxDistanceMeters;

MODIFY
src/server/rest/v1/service/security/SettingSecurity.ts
src/server/rest/v1/service/security/SettingSecurity.ts
@@ -43,12 +43,12 @@ export default class SettingSecurity {
sensitiveData: request.sensitiveData ? request.sensitiveData.map(sanitize) : []
} as SettingDB;
// Check Content
- if (request.content) {
+ if (Utils.objectHasProperty(request, 'content')) {
settings.content = {
type: request.content.type
} as SettingDBContent;
// Check Links
- if (request.content.links) {
+ if (Utils.objectHasProperty(request.content, 'links')) {
settings.content.links = request.content.links.map((link: SettingLink) => ({
id: link.id,
name: link.name,
@@ -67,12 +67,12 @@ export default class SettingSecurity {
break;
case RoamingSettingsType.GIREVE:
settings.content.ocpi = {} as OcpiSetting;
- if (request.content.ocpi.businessDetails) {
+ if (Utils.objectHasProperty(request.content.ocpi, 'businessDetails')) {
settings.content.ocpi.businessDetails = {
name: sanitize(request.content.ocpi.businessDetails.name),
website: sanitize(request.content.ocpi.businessDetails.website)
} as OcpiBusinessDetails;
- if (request.content.ocpi.businessDetails.logo) {
+ if (Utils.objectHasProperty(request.content.ocpi.businessDetails, 'logo')) {
settings.content.ocpi.businessDetails.logo = {
url: sanitize(request.content.ocpi.businessDetails.logo.url),
thumbnail: sanitize(request.content.ocpi.businessDetails.logo.thumbnail),
@@ -83,19 +83,19 @@ export default class SettingSecurity {
};
}
}
- if (request.content.ocpi.cpo) {
+ if (Utils.objectHasProperty(request.content.ocpi, 'cpo')) {
settings.content.ocpi.cpo = {
countryCode: sanitize(request.content.ocpi.cpo.countryCode),
partyID: sanitize(request.content.ocpi.cpo.partyID)
};
}
- if (request.content.ocpi.emsp) {
+ if (Utils.objectHasProperty(request.content.ocpi, 'emsp')) {
settings.content.ocpi.emsp = {
countryCode: sanitize(request.content.ocpi.emsp.countryCode),
partyID: sanitize(request.content.ocpi.emsp.partyID)
};
}
- if (request.content.ocpi.currency) {
+ if (Utils.objectHasProperty(request.content.ocpi, 'currency')) {
settings.content.ocpi.currency = request.content.ocpi.currency;
}
break;

MODIFY
src/server/rest/v1/service/security/SiteAreaSecurity.ts
src/server/rest/v1/service/security/SiteAreaSecurity.ts
@@ -49,7 +49,7 @@ export default class SiteAreaSecurity {
WithAvailableChargers: !request.WithAvailableChargers ? false : UtilsSecurity.filterBoolean(request.WithAvailableChargers),
SiteID: sanitize(request.SiteID)
} as HttpSiteAreasRequest;
- if (request.Issuer) {
+ if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
if (Utils.containsGPSCoordinates([request.LocLongitude, request.LocLatitude])) {
@@ -57,7 +57,7 @@ export default class SiteAreaSecurity {
Utils.convertToFloat(sanitize(request.LocLongitude)),
Utils.convertToFloat(sanitize(request.LocLatitude))
];
- if (request.LocMaxDistanceMeters) {
+ if (Utils.objectHasProperty(request, 'LocMaxDistanceMeters')) {
request.LocMaxDistanceMeters = Utils.convertToInt(sanitize(request.LocMaxDistanceMeters));
if (request.LocMaxDistanceMeters > 0) {
filteredRequest.LocMaxDistanceMeters = request.LocMaxDistanceMeters;

MODIFY
src/server/rest/v1/service/security/SiteSecurity.ts
src/server/rest/v1/service/security/SiteSecurity.ts
@@ -69,7 +69,7 @@ export default class SiteSecurity {
public static filterSitesRequest(request: any): HttpSitesRequest {
const filteredRequest: HttpSitesRequest = {} as HttpSitesRequest;
- if (request.Issuer) {
+ if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
filteredRequest.Search = sanitize(request.Search);
@@ -84,7 +84,7 @@ export default class SiteSecurity {
Utils.convertToFloat(sanitize(request.LocLongitude)),
Utils.convertToFloat(sanitize(request.LocLatitude))
];
- if (request.LocMaxDistanceMeters) {
+ if (Utils.objectHasProperty(request, 'LocMaxDistanceMeters')) {
request.LocMaxDistanceMeters = Utils.convertToInt(sanitize(request.LocMaxDistanceMeters));
if (request.LocMaxDistanceMeters > 0) {
filteredRequest.LocMaxDistanceMeters = request.LocMaxDistanceMeters;

MODIFY
src/server/rest/v1/service/security/TransactionSecurity.ts
src/server/rest/v1/service/security/TransactionSecurity.ts
@@ -6,7 +6,7 @@ import sanitize from 'mongo-sanitize';
export default class TransactionSecurity {
public static filterTransactionsRefund(request: any): HttpTransactionsRefundRequest {
- if (!request.transactionIds) {
+ if (!Utils.objectHasProperty(request, 'transactionIds')) {
return { transactionIds: [] };
}
return { transactionIds: request.transactionIds.map(sanitize) };
@@ -65,13 +65,13 @@ export default class TransactionSecurity {
filteredRequest.RefundStatus = sanitize(request.RefundStatus);
filteredRequest.MinimalPrice = sanitize(request.MinimalPrice);
filteredRequest.ConnectorID = sanitize(request.ConnectorID);
- if (request.Statistics) {
+ if (Utils.objectHasProperty(request, 'Statistics')) {
filteredRequest.Statistics = sanitize(request.Statistics);
}
- if (request.UserID) {
+ if (Utils.objectHasProperty(request, 'UserID')) {
filteredRequest.UserID = sanitize(request.UserID);
}
- if (request.ReportIDs) {
+ if (Utils.objectHasProperty(request, 'ReportIDs')) {
filteredRequest.ReportIDs = sanitize(request.ReportIDs);
}
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
@@ -91,7 +91,7 @@ export default class TransactionSecurity {
filteredRequest.Search = sanitize(request.Search);
filteredRequest.ErrorType = sanitize(request.ErrorType);
filteredRequest.ConnectorID = sanitize(request.ConnectorID);
- if (request.UserID) {
+ if (Utils.objectHasProperty(request, 'UserID')) {
filteredRequest.UserID = sanitize(request.UserID);
}
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);

MODIFY
src/server/rest/v1/service/security/UserSecurity.ts
src/server/rest/v1/service/security/UserSecurity.ts
@@ -39,40 +39,40 @@ export default class UserSecurity {
public static filterUsersRequest(request: any): HttpUsersRequest {
const filteredRequest = {} as HttpUsersRequest;
- if (request.Issuer) {
+ if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
- if (request.WithTag) {
+ if (Utils.objectHasProperty(request, 'WithTag')) {
filteredRequest.WithTag = UtilsSecurity.filterBoolean(request.WithTag);
}
- if (request.Search) {
+ if (Utils.objectHasProperty(request, 'Search')) {
filteredRequest.Search = sanitize(request.Search);
}
- if (request.SiteID) {
+ if (Utils.objectHasProperty(request, 'SiteID')) {
filteredRequest.SiteID = sanitize(request.SiteID);
}
- if (request.Role) {
+ if (Utils.objectHasProperty(request, 'Role')) {
filteredRequest.Role = sanitize(request.Role);
}
- if (request.Status) {
+ if (Utils.objectHasProperty(request, 'Status')) {
filteredRequest.Status = sanitize(request.Status);
}
- if (request.ErrorType) {
+ if (Utils.objectHasProperty(request, 'ErrorType')) {
filteredRequest.ErrorType = sanitize(request.ErrorType);
}
- if (request.ExcludeSiteID) {
+ if (Utils.objectHasProperty(request, 'ExcludeSiteID')) {
filteredRequest.ExcludeSiteID = sanitize(request.ExcludeSiteID);
}
- if (request.TagID) {
+ if (Utils.objectHasProperty(request, 'TagID')) {
filteredRequest.TagID = sanitize(request.TagID);
}
- if (request.ExcludeUserIDs) {
+ if (Utils.objectHasProperty(request, 'ExcludeUserIDs')) {
filteredRequest.ExcludeUserIDs = sanitize(request.ExcludeUserIDs);
}
- if (request.IncludeCarUserIDs) {
+ if (Utils.objectHasProperty(request, 'IncludeCarUserIDs')) {
filteredRequest.IncludeCarUserIDs = sanitize(request.IncludeCarUserIDs);
}
- if (request.NotAssignedToCarID) {
+ if (Utils.objectHasProperty(request, 'NotAssignedToCarID')) {
filteredRequest.NotAssignedToCarID = sanitize(request.NotAssignedToCarID);
}
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
@@ -157,37 +157,37 @@ export default class UserSecurity {
private static _filterUserRequest(request: any, loggedUser: UserToken): Partial<User> {
const filteredRequest: Partial<User> = {};
- if (request.costCenter) {
+ if (Utils.objectHasProperty(request, 'costCenter')) {
filteredRequest.costCenter = sanitize(request.costCenter);
}
- if (request.firstName) {
+ if (Utils.objectHasProperty(request, 'firstName')) {
filteredRequest.firstName = sanitize(request.firstName);
}
- if (request.iNumber) {
+ if (Utils.objectHasProperty(request, 'iNumber')) {
filteredRequest.iNumber = sanitize(request.iNumber);
}
- if (request.image) {
+ if (Utils.objectHasProperty(request, 'image')) {
filteredRequest.image = sanitize(request.image);
}
- if (request.mobile) {
+ if (Utils.objectHasProperty(request, 'mobile')) {
filteredRequest.mobile = sanitize(request.mobile);
}
- if (request.name) {
+ if (Utils.objectHasProperty(request, 'name')) {
filteredRequest.name = sanitize(request.name);
}
- if (request.locale) {
+ if (Utils.objectHasProperty(request, 'locale')) {
filteredRequest.locale = sanitize(request.locale);
}
- if (request.address) {
+ if (Utils.objectHasProperty(request, 'address')) {
filteredRequest.address = UtilsSecurity.filterAddressRequest(request.address);
}
- if (request.passwords && request.passwords.password && request.passwords.password.length > 0) {
+ if (Utils.objectHasProperty(request, 'passwords') && request.passwords.password && request.passwords.password.length > 0) {
filteredRequest.password = sanitize(request.passwords.password);
}
- if (request.phone) {
+ if (Utils.objectHasProperty(request, 'phone')) {
filteredRequest.phone = sanitize(request.phone);
}
- if (request.email) {
+ if (Utils.objectHasProperty(request, 'email')) {
filteredRequest.email = sanitize(request.email);
}
if (Utils.objectHasProperty(request, 'issuer')) {
@@ -199,17 +199,17 @@ export default class UserSecurity {
// Admin?
if (Authorizations.isAdmin(loggedUser) || Authorizations.isSuperAdmin(loggedUser)) {
// Ok to set the sensitive data
- if (request.status) {
+ if (Utils.objectHasProperty(request, 'status')) {
filteredRequest.status = sanitize(request.status);
}
- if (request.plateID) {
+ if (Utils.objectHasProperty(request, 'plateID')) {
filteredRequest.plateID = sanitize(request.plateID);
}
- if (request.role) {
+ if (Utils.objectHasProperty(request, 'role')) {
filteredRequest.role = sanitize(request.role);
}
}
- if (request.notifications) {
+ if (Utils.objectHasProperty(request, 'notifications')) {
filteredRequest.notifications = UserSecurity.filterNotificationsRequest(request.role, request.notifications);
}
return filteredRequest;

MODIFY
src/server/rest/v1/service/security/UtilsSecurity.ts
src/server/rest/v1/service/security/UtilsSecurity.ts
@@ -26,7 +26,7 @@ export default class UtilsSecurity {
static filterSort(request: any, filteredRequest): void {
// Exist?
- if (request.SortFields) {
+ if (Utils.objectHasProperty(request, 'SortFields')) {
// Sanitize
request.SortFields = sanitize(request.SortFields);
const sortFields = request.SortFields.split('|');
@@ -73,7 +73,7 @@ export default class UtilsSecurity {
static filterLimit(request: any, filteredRequest: any): void {
// Exist?
- if (!request.Limit) {
+ if (!Utils.objectHasProperty(request, 'Limit')) {
// Default
filteredRequest.Limit = Constants.DB_RECORD_COUNT_DEFAULT;
} else {
@@ -90,7 +90,7 @@ export default class UtilsSecurity {
static filterSkip(request: any, filteredRequest: any): void {
// Exist?
- if (!request.Skip) {
+ if (!Utils.objectHasProperty(request, 'Skip')) {
// Default
filteredRequest.Skip = 0;
} else {
@@ -115,7 +115,7 @@ export default class UtilsSecurity {
filteredAddress.department = sanitize(address.department);
filteredAddress.region = sanitize(address.region);
filteredAddress.country = sanitize(address.country);
- if (address.coordinates && address.coordinates.length === 2) {
+ if (Utils.objectHasProperty(address, 'coordinates') && address.coordinates.length === 2) {
filteredAddress.coordinates = [
sanitize(address.coordinates[0]),
sanitize(address.coordinates[1])
@@ -128,7 +128,7 @@ export default class UtilsSecurity {
static filterAddressCoordinatesRequest(address: Address): Address {
const filteredAddress: Address = {} as Address;
if (address) {
- if (address.coordinates && address.coordinates.length === 2) {
+ if (Utils.objectHasProperty(address, 'coordinates') && address.coordinates.length === 2) {
filteredAddress.coordinates = [
sanitize(address.coordinates[0]),
sanitize(address.coordinates[1])
@@ -139,20 +139,20 @@ export default class UtilsSecurity {
}
static filterCreatedAndLastChanged(filteredEntity: any, entity: any, loggedUser: UserToken): void {
- if (entity.createdBy && typeof entity.createdBy === 'object' &&
- entity.createdBy.id && Authorizations.canReadUser(loggedUser, entity.createdBy.id)) {
+ if (Utils.objectHasProperty(entity, 'createdBy') && typeof entity.createdBy === 'object' &&
+ Utils.objectHasProperty(entity.createdBy, 'id') && Authorizations.canReadUser(loggedUser, entity.createdBy.id)) {
// Build user
filteredEntity.createdBy = Utils.buildUserFullName(entity.createdBy, false);
}
- if (entity.lastChangedBy && typeof entity.lastChangedBy === 'object' &&
+ if (Utils.objectHasProperty(entity, 'lastChangedBy') && typeof entity.lastChangedBy === 'object' &&
entity.lastChangedBy.id && Authorizations.canReadUser(loggedUser, entity.lastChangedBy.id)) {
// Build user
filteredEntity.lastChangedBy = Utils.buildUserFullName(entity.lastChangedBy, false);
}
- if (entity.lastChangedOn) {
+ if (Utils.objectHasProperty(entity, 'lastChangedOn')) {
filteredEntity.lastChangedOn = entity.lastChangedOn;
}
- if (entity.createdOn) {
+ if (Utils.objectHasProperty(entity, 'createdOn')) {
filteredEntity.createdOn = entity.createdOn;
}
}

added objectHasProperty to ifs in security files