This is a quite convoluted story. But in short: the common story is a bit too short for correctness. The Versailles Treaty was quite bad on many accounts, but it was not really responsible alone for what happened to aspirin.
The classical account is this:
In 1915, Aspirin manufactured in tablet form became available without a prescription. As soon as the First World War ended and Germany surrendered, Bayer had to give away its registered trademark of Aspirin. Thus "Aspirin" became a generic name in the countries that emerged as winners of the war but remained a registered trademark of Bayer in countries like Germany, Mexico, Canada and over 80 other countries. After the patents ended many pharmaceutical companies in America began the mass production of Aspirin. Their campaigns were destined to be doomed. The First World War had ended but Bayer's war against the world had just begun.
— G. Tsoucalas, M. Karamanou, G. Androutsos: "Travelling through Time with Aspirin, a Healing Companion", European Journal of Inflammation Vol. 9, no. I, 13–16 (2011).
This is not entirely false, and neither it is entirely true. It's an oversimplification and "Versailles" may be a nice shorthand to mark time, but it has not that much to do with what actually happened in the history of aspirin.
We have to observe a few aspects: knowledge to produce it, the corresponding patents, the trademark, and the trade in kind. And in which markets which events occurred.
In Britain the patent for Aspirin was already lost in 1905, as a court ruled that prior art from 1869 made it an invalid claim. But it upheld Bayer's trademark. Generics were thus allowed. In the US both claims were ruled valid. Such trademarks are country specific: In many countries, like Germany itself, the aspirin trademark never went out of Bayer's control.
Thus an all important qualifier: Only in the victorious allied countries/markets did Bayer lose its registered trademarks. In some countries like Britain and the US this situation was used for profit, in revolutionary Russia the trademark entry was just deleted from its register.
As was the frequent practice of the time, the launch of this product was accompanied by numerous applications for patent registration for the invention itself, and trademark registration for the name. These applications were made in Germany but also in a range of other countries, including Great Britain and the United States. In Britain, patent application 27,088 was lodged on 22 December 1898 and granted to a British resident, Henry Edward Newton. In the United States, Patent No. 644,077 – lodged on 1 August 1898 and granted 22 February 1900 – was issued to Felix Hoffman. Despite being essentially the same invention, when Bayer initiated infringement action in courts in Britain and the United States, and the defendants countersued for revocation of the patents, those courts reached different opinions on their validity.
— Dan Hunter & Claudy Op Den Kamp (Eds): "A History Of Intellectual Property In 50 Objects", Cambridge University Press: Cambridge, New York, 2019. (Chapter 25: Aspirin Pill, pp209–215.)
And in effect Bayer already had a problem aside from but related to marketing rights: consumer perception and brand recognition. Aspirin was well underway to become genericised, and the US patent was about to expire in 1917:
We see here a more classical move. When the protection via the technological assets is about to expire, companies tend to turn to the market-based assets. While the initial building of the Aspirin brand name had not required heavy communication investments, Bayer was finally deciding to start investing in the brand. However, at that stage the brand recognition was already largely established and the investments that started in 1914 were essentially needed to reinforce and maintain the brand (and thus reinforce the distribution channels). Adopting a counterfactual perspective, one could imagine that building a brand from scratch at that point would most certainly have cost much more. In any case, the outbreak of WWI did not permit to pursue such investments.
— Klaus Jennewein, Thomas Durand and Alexander Gerybadze: "When Brands Complement Patents in Securing the Returns from Technological Innovation: The Case of Bayer Aspirin", Management international / Gestiòn Internacional / International Management, 14 (3), 2010. pp73–86.
In allied countries the very outbreak of the war made for a veritable "aspirin-crisis". Stocks running out, no re-supply on the horizon and a public with more than enough reasons for headaches. This made governments bend the rules. In Britain the trademark for ASPIRIN was just completely suspended to allow competitors to sell their acetylic salicylic acid (ASS/ASA) even under the brand name.
In 1915 an Australian parliamentarian came up with the idea that "trading with the enemy was helping him" and called specific attention to Aspirin. (Later debate example)
In the US, entering the war made seizure of enemy owned assets easy. Bayer tried to hide their's behind shell-companies, but the government saw through the veil and took action against those in 1917. With the Office of Alien Property Custodian. The government arranged for the German assets to be force sold. Sterling Drug bought Aspirin and other Bayer assets in 1918. As the linked article shows, that was not really that much cutting of Bayer from making profits, as they soon entered into a business partnership…
This was all nice and back in the barn before anyone important showed up in Paris:
The war ended in November 1918, just a year after the passage of the Trading with the Enemy Act. In that time, the Alien Property Custodian had acquired hundreds of millions of dollars in private property. In a move that was later widely criticized – and that political allies of the Alien Property Custodian likely profited from directly – Palmer announced that all of the seized property would be “Americanized,” or sold to U.S. citizens, partly in the hopes of crippling German industries. (His attitude echoed a wider sentiment that the Central Powers deserved to pay dearly for the vast destruction of the war.) In one high-profile example, the chemical company Bayer was auctioned on the steps of its factory in New York. Bayer lost its U.S. patent for aspirin, one of the most valuable drugs ever produced.
— Daniel A. Gross: "The U.S. Confiscated Half a Billion Dollars in Private Property During WWI. America’s home front was the site of interment, deportation, and vast property seizure", Smithonian, 2014.
After Versailles: As part of the reparations not only money and gold were to be supplied by Germany, but also useful things in kind, like coal — or aspirin; but in pill form.
The US rights to the trademark was then only lost in 1921. (Bayer Co. v. United Drug Co., 272 F. 505 (S.D.N.Y. 1921))
What about Versailles?
The implication was clear. Aspirin was going to be sold with all the hype, fanfare and panache that a hardened patent-remedy professional could bring to bear. Even more boldly, Weiss and his colleagues also decided that there was no reason why their Bayer Aspirin and the other drugs should be marketed only in the United States. As Leverkusen's intellectual property rights were under attack all over the Allied world, why shouldn't Sterling try to challenge them overseas too?
It all sounded fine in theory, but there was a problem. When all was said and done, Sterling Products was still just a patent medicine business. Its bosses had no idea how to go about making the sophisticated drugs they now owned and the vast modern Rensselaer plant was completely mystifying to them. The German managers who had once run its production lines had all been sacked, interned or deported, and perhaps understandably hadn't left behind a handy set of instructions showing how everything worked. Nor was there any help from the Bayer patents. Sterling's executives found them as confusing as Mr Justice Joyce had so many years earlier. The documents truly were 'erroneous and misleading … by accident, error or design so framed as to obscure the subject as much as possible'. There was still a large amount of product stockpiled at Rensselaer, but it wouldn't last for ever. Unless Sterling Products found a way to get the plant working, its $5.3 million investment could turn out to be one of the worst bargains in history.
There was, of course, one possible solution, but it was not an attractive one. Sterling Products could try to get help from Rensselaer's former owners, Farbenfabriken Bayer. As these were the very people whose interests Sterling was now plotting to undermine, the 'alien' company that the American government had been so keen to get shot of, it didn't look a promising route to follow. There was a strong chance that the Germans wouldn't even talk to them. Fortunately there was one former Bayer executive still with the company, its export manager, Ernst Moller. He had kept his head down during the wartime farragos that had overwhelmed the other senior managers and had somehow clung on to his job. Seeing an opportunity to establish himself in the Sterling hierarchy and pay off a few debts to his old employers in the process, he offered himself as a middleman and pressed Weiss to do the only thing open to him. Go to Germany and cut a deal.
Had Carl Duisberg known what they were planning he would probably have enjoyed the delicious irony of Sterling's dilemma, but right then he had other things on his mind. At the end of April 1919, the German government's delegation arrived at Versailles to begin negotiating a peace treaty that would formally end the war. The hopes of the nation had gone with them. Many Germans hoped that the Allies would stick to the principles set out by President Woodrow Wilson in January 1918. His 'Fourteen Points' had covered such matters as the restoration of conquered territory, independence for nations such as Poland and removal of trade barriers, but otherwise seemed to offer a reassuring blueprint for a 'just peace'. In fact it all looked so reasonable that there was even optimism that Germany might get back some of its own lost assets. Among the delegates was a representative of the embryonic IG Farben combine, Carl Bosch of BASF, who hoped to secure the return of thousands of the group's patents, products, factories and trademarks still in Allied hands. Like everyone else with such interests overseas, Duisberg and the management of Farbenfabriken Bayer were on tenterhooks as to what Bosch might achieve.
It didn't take long for disillusionment to set in.
It seemed the German delegation had not been invited to Versailles as equal negotiating partners, but as inferiors who were to be given a set of demands to which they were expected to agree. Shortly after their arrival they were presented with the first draft of the peace treaty – a document that they had had no hand in drawing up. It contained no mention of any of their seized assets or indeed of anything approximating to a 'just peace'. President Wilson, perhaps weakened by the long-term effects of the flu, had clearly lost his battle to persuade the Allies of the importance of allowing the Germans some shreds of dignity. The other victors, particularly the French, seemed more set on making the vanquished pay for their losses and preventing them from ever becoming a threat again.
The final document, signed by the demoralized and browbeaten losers on 28 June, was savagely retributive. Germany lost about 13 per cent of its territory, including all its overseas colonies. Its army was reduced to a rump of 100,000 men, and most of its and the navy's weapons were confiscated. The Rhineland was to be occupied and permanently demilitarized and France was given control of the industrially rich Saar region. To cap it all, the financial reparations demanded were almost impossibly high – sums far in excess of Germany's capacity to pay.
For Farbenfabriken Bayer and IG Farben the treaty was a disaster. As a grim-faced Carl Bosch explained on his return, one of its most damaging reparations conditions was that Germany had to immediately surrender 50 per cent of its chemical, dyes and pharmaceutical stocks. Even worse, for the next five years the Allies would be able to buy a quarter of any of those products at prices well below market rates. Not one seized trademark or product had been handed back, nor did it look as though they ever would. Short of a miracle, Carl Duisberg would have to accept the unthinkable. In much of the Allied world, Bayer's once jealously guarded aspirin monopoly was gone for good.
— Diarmuid Jeffreys: "Aspirin. The Remarkable Story of a Wonder Drug", Bloomsbury: London, 2004.
The treaty itself was quite prosaic in cementing just a fait accompli:
Nevertheless, all acts done by virtue of the special measures taken during the war under legislative, executive or administrative authority of any Allied or Associated Power in regard to the rights of German nationals in industrial, literary or artistic property shall remain in force and shall continue to maintain their full effect.
— Treaty of Versailles/Part X, Economic Clauses, Section II, Treaties, Article 306. As published in German offical translation in Reichsgesetzblatt I 1919, S. 687 ff.; S. 1.185.
It's getting too long to look into the specifics for heroin in this answer. Just note that patent & trademark wise the situation was similar, but the outlook on profitability much reduced as the International Opium Convention was shoehorned into the Versailles treaty.
Previously, Germany, Austria and the Ottoman Empire weren't much in favour of regulating this, but the treaty was quite the opportunity. This increased the political pressure and Bayer 'voluntarily' stopped manufacturing the drug in 1931 after it was already banned in the US in 1924. (Cf Jens Soentgen: "Heroin. Taming a drug and losing control", in:
Bernadette Bensaude Vincent et al. (Eds): "Research Objects in their Technological Setting", History and Philosophy of Technoscience 10, Routledge: Abigndon, New York, 2017. (pp89–104))