The interconnection of local energy networks (LENs) enables efficient exchange of energy and flexibility among them, fostering the integration of distributed energy resources and demand-side management strategies. Thus, the interconnected local energy systems (ILEN) structure is a viable approach to electrical distribution systems’ operation and management. However, implementing distributed energy management structures such as ILEN entails a great amount of information transactions. Therefore, these structures are more vulnerable to cyber threats. Thus, the newly developed efficient and secure power systems’ operation methods should take digitalization-related security risks into account. As a result, this paper is focused on the development of a secure operation method, equipped with a hybrid algorithm to mitigate cyber threats in the context of ILEN. In this regard, this research proposes a novel hybrid XGBoost-based cyber threat mitigation (HXGBTM) method to cope with the vulnerabilities of the physical and information layers of the cyber-infrastructure. The proposed cyber threat mitigation method is built upon the classification and regression capabilities of the XGBoost ensemble of decision trees to identify and mitigate anomalies in the electrical consumption data. Therefore, in the first step, the ILEN’s multi-objective energy and flexibility scheduling problem considering demand response portfolio i.e., is developed that encompasses a bi-level optimization problem, in which the operator of the ILEN optimizes energy and flexibility trading in the upper level. While in the lower level, each LEN operator minimizes scheduling costs along with maximizing the local flexibility as well as providing a demand response portfolio as a negawatt resource. Here, the flexibility index, which is later maximized using the second objective function, is considered as the proportion between "the available ramping capacity" and "required ramping capacity". In this paper, direct load control, and interruptible/curtailable demand response comprehensive models are implemented as candidate programs for the suggested portfolio. Furthermore, a hybrid cyber threat is modeled considering the communication line intrinsic vulnerability, as a result of natural causes, wear, and aging of the infrastructure etc., as well as false data injection (FDI) attacks that target each LEN’s electrical consumption database. Finally, the proposed HXGBTM is employed to mitigate the above-mentioned cyber-vulnerabilities and achieve near real-world conditions.