A document presumably authored by Osama bin Laden in 2007 refers to Iran as al Qaeda’s “main artery for funds, personnel, and communication.” That same letter referred to the “hostages” held by Iran, meaning those al Qaeda figures who were held in some form of detention and not allowed to freely operate. Bin Laden was not against attacking Iran in principle; he simply did not think the costs of such action were worth it.
Iran’s relationship with al Qaeda has survived for years, despite numerous disagreements and conflicts between the two. For instance, one file recovered in bin Laden’s Abbottabad lair shows that he was troubled by Iran’s attempt to expand across the Middle East and he conceived of a plan to combat the Shiite jihadists’ growing footprint. Al Qaeda has also kidnapped Iranian diplomats in order force hostage exchanges. Several high-level al Qaeda leaders were reportedly released as part of one such exchange in 2015, although their status beforehand inside Iran was murky.
Most importantly, the two sides are clearly at odds in Syria and Yemen, where they have fought each other and affiliated proxies for several years.
Yet, throughout all of this, Iran has allowed al Qaeda to maintain a key facilitation hub.
In July 2016, for instance, the US Treasury Department sanctioned three senior al Qaeda leaders “located in Iran.” One of them, Faisal Jassim Mohammed Al Amri Al Khalidi (a.k.a. Abu Hamza al Khalidi), has served as al Qaeda’s “Military Commission Chief” — meaning he was one of the most important figures in the group’s international network. Al Khalidi was identified in Osama bin Laden’s files as part of a “new generation” of leadership al Qaeda groomed to replace their fallen comrades. As Treasury’s July 2016 designations made clear, some of al Qaeda’s most important men continued to operate inside Iran. [See FDD’s Long War Journal report, Treasury designates 3 senior al Qaeda members in Iran.]
http://www.longwarjournal.org/archives/2017/07/state-department-iran-continues-to-host-al-qaedas-core-facilitation-pipeline.php