TIF: Learning Temporal Invariance in Android Malware Detectors

Xinran Zheng, Shuo Yang, Edith C. H. Ngai, Suman Jana, Lorenzo Cavallaro

TL;DR

Android malware detectors quickly lose accuracy over time because standard machine learning models latch onto temporary statistical shortcuts rather than core malicious intent. This paper introduces TIF (Temporal Invariant Training Framework), a novel training paradigm that forces models to learn time-invariant features by slicing training data chronologically and aligning optimization gradients across eras. TIF significantly slows down detector aging across diverse feature spaces and cuts continual learning annotation costs by over 41%.

What Problem Does This Paper Address?

Machine learning-based Android malware detectors suffer from a phenomenon known as "detector aging." A model that achieves 99% accuracy on today's data might perform terribly two years from now. This degradation is driven by natural distribution drift: malware authors continuously update their code to bypass OS restrictions, and entirely new malware families emerge over time.

Standard models are trained using Empirical Risk Minimization (ERM), which assumes all training data comes from a single, stationary distribution. ERM acts like a student cramming for an exam by memorizing patterns; it indiscriminately latches onto "statistical shortcuts"—features that happen to be highly predictive during the training period but change or disappear later (such as specific API names or implementation artifacts).

Existing solutions either rely on rigid assumptions about what causes drift (e.g., tracking API renaming) or use Continual Learning (CL) to constantly update models. However, CL is incredibly expensive because it requires continuous, manual labeling by security experts. This paper asks a fundamental question: Can we explicitly exploit historical training data to learn stable, invariant malicious signatures without relying on frequent model updates?

Fig. 1: The top-10 families’ proportions vary over time; zero marks the test start, negatives indicate training.

Methods

TIF adapts Invariant Learning Theory to the complex, imbalanced world of malware detection. Instead of treating the training dataset as a flat monolith, TIF introduces a two-stage framework:

  1. Training Environments Segmentation: TIF automatically partitions historical training data into chronological windows (e.g., months or quarters). Each window is treated as a distinct "environment." Slicing the data this way naturally exposes the model to temporal drift during training.
  2. Multi-Proxy Contrastive Learning (MPC): Malware classes are highly diverse and structurally imbalanced. Treating all malware samples uniformly forces the model to ignore sub-family variations. TIF solves this by assigning multiple learnable "proxies" to each class. Samples are softly assigned to these proxies, preserving intra-class diversity and mapping out complex feature spaces.
  3. Invariant Gradient Alignment (IGA): Inspired by Invariant Risk Minimization (IRM), IGA uses environment-specific dummy classifiers to evaluate the model's empirical risk across different eras. It forces the feature encoder to align its optimization gradients across all time windows. If a feature is highly predictive in Month 1 but useless in Month 6, IGA suppresses it, forcing the network to focus on features that remain stable across all environments.

Datasets

The authors evaluated TIF on a massive, decade-long dataset spanning 2014 to June 2025, constructed by extending the well-known Transcendent benchmark with newly collected samples from Androzoo.

  • Total Size: 308,637 benign applications and 48,707 malicious applications.
  • Evaluation Protocol: To strictly simulate real-world deployment and avoid temporal bias, the models were trained only on data from 2014 and tested progressively on the subsequent ten years (2015–2025).

Key Insights and Ideas

  • Intent over Implementation: While concrete implementation details (like specific control flows or APIs) change as Android evolves, the underlying malicious intent of a malware family remains stable. For instance, adware must always detect when a user is active to inject ads, regardless of whether it uses an old TimerTask or a modern BroadcastReceiver. TIF successfully shifts the model's focus from brittle implementation details to these intent-level prerequisites.
  • The ERM Trap: Features that appear highly discriminative during standard training are often the least stable over time. ERM models overfit to these transient patterns, leading to rapid post-deployment degradation.
  • Time as an Agnostic Proxy: You don't need to explicitly model the root causes of drift (like market demands or OS updates). Chronological partitioning serves as an effective, all-encompassing proxy for capturing the combined effects of natural evolution.
Fig. 3: (a) and (b) illustrate changes in the discriminability of the top 10 discriminative training features and the top 10 important testing features, respectively. “Discriminability” is defined as the absolute difference in active ratios between benign and malicious samples. The grey dotted line indicates the start of the testing phase, with preceding values representing each feature’s discriminability across months in the training set.

Key Results

The authors tested TIF across three major Android malware feature spaces: DeepDrebin (binary behavioral features), Malscan (graph-based centrality features), and BERTroid (permission-language embeddings).

  • Slowing Down Aging: TIF consistently outperformed state-of-the-art static defense baselines (such as APIGraph and T-stability). In the first year of deployment, TIF achieved up to an 8% relative improvement in Area Under Time (AUT) macro-F1, performing nearly as well as an idealized model that is manually retrained every single month with fresh labels.
  • Slashing Maintenance Costs: When integrated into an active continual learning pipeline, TIF's robust representations delayed model degradation. It reduced the number of required model updates from 65 down to 38—cutting expert annotation and retraining costs by 41.5% without sacrificing any detection accuracy.

Limitations and Future Work

  • Training Overhead: TIF requires a two-stage training process and extra loss calculations. This increases offline training time compared to standard ERM (though it introduces absolutely zero overhead during inference/deployment).
  • Granularity Selection: The performance of TIF is sensitive to how finely the training environments are sliced (e.g., monthly vs. quarterly). The optimal granularity depends on the velocity of the drift, which currently must be tuned manually.
  • Natural vs. Adversarial Drift: TIF is explicitly designed to combat natural malware evolution. It does not account for adaptive, adversarial attacks where a hacker intentionally manipulates code features with explicit knowledge of the detector. The authors flag adversarial invariant learning as a vital next step.

Summary updated

Abstract

Learning-based Android malware detectors degrade over time due to natural distribution drift caused by malware variants and new families. This paper systematically investigates the challenges classifiers trained with empirical risk minimization (ERM) face against such distribution shifts and attributes their shortcomings to their inability to learn \emph{stable} discriminative features. Invariant learning theory offers a promising solution by encouraging models to generate stable representations across environments that expose the instability of the training set. However, the lack of prior environment labels, the diversity of drift factors, and low-quality representations caused by diverse families make this task challenging. To address these issues, we propose TIF, the first temporal invariant training framework for malware detection, which aims to enhance the ability of detectors to learn stable representations across time. TIF organizes environments based on application observation dates to reveal temporal drift, integrating specialized multi-proxy contrastive learning and invariant gradient alignment to generate and align environments with high-quality, stable representations. TIF can be seamlessly integrated into any learning-based detector. Experiments on a decade-long dataset show that TIF excels, particularly in early deployment stages, addressing real-world needs and outperforming state-of-the-art methods.
BibTeX
@article{zheng2026tif,
  author = {Xinran Zheng and Shuo Yang and Edith C. H. Ngai and Suman Jana and Lorenzo Cavallaro},
  title = {{TIF: Learning Temporal Invariance in Android Malware Detectors}},
  journal = {IEEE Trans. Software Eng.},
  year = {2026},
  doi = {10.1109/tse.2026.3698484},
}
Figure