The proposed legislation will have a direct impact on how Apple skims commissions from in-app purchases.

Apple is facing one of the biggest challenges yet to how it controls and profits from the App Store, according to reporting in the Wall Street Journal. This comes as Europe prepares to complete a new competition law in the coming weeks.

Lawmakers could finish the new European Union legislation as soon as this month. The law, called the Digital Markets Act, will direct Apple to allow software to be downloaded outside its cash-generating App Store, a practice called “sideloading.”

The law will also limit how companies impose their own payment systems on apps, according to people involved in the negotiations. Failure to comply would carry penalties of up to tens of billions of dollars.

Apple’s “walled garden” is under siege

Apple openly opposes the DMA. For the past two years, the company has battled lawmakers, regulators and rivals around the world to defend how it serves as the gate keeper to more than one billion users of its devices. The company maintains that sideloading would make iPhone users vulnerable to security and privacy risks. Apple vets each app before allowing it into the App Store, and has said that sideloading would disrupt the “trusted ecosystem” the company has created.

The company told the Wall Street Journal that “governments and international agencies world-wide have explicitly advised against sideloading requirements.” They added that such a law “would cripple the privacy and security protections that users have come to expect.”

The EU however, disagrees. Google allows sideloading apps on Android, even though it does bring with it a higher risk of malware and other security issues. Still, sideloading isn’t a common practice and most users get their apps from the Google Play store.

EU antitrust commissioner Margrethe Vestager has previously dismissed Apple’s concerns. Last year she declared that “customers will not give up neither security nor privacy if they use another app store or if they sideload.”

TIP: Also read our story on how the Dutch market authority ACM fines Apple 5 million Euros a week for ignoring antitrust ruling.