I don't think that's a particularly loose office grapevine. Given that the friend knows the OP, she may have been given that info precisely to pass it to the OP. Maybe she knew it because it was pat of her job to know it.
Were I the OP's friend, if I knew that she had come SO close to getting an offer, and if I knew why she didn't get it, and that reason was either (a) nothing to do with her; or (b) something she could successfully tweak; I'd absolutely tell her everything I knew.
And I think that Nebulous was perfectly fine--in Etiquette and in Integrity--to ask her friend to continue with the story.
But Nebulous, I think this is GOOD to know. Now you know they like your skills, etc. That's great feedback. Your ego should be stoked.
OK, OK, you didn't get the job. But you had a really serious shot at TWO of them. You may have been the top candidate for both. One job went to an insider, and the other disappeared. But wow--you're hot stuff! And these people think so.
Jocelyn is right--if you're at all interested, now's the time to drop them a note. And do so every few months or so, in a "cold call" to say, "I'm still very interested in working for your company, and I wanted you to know in case any organizational decisions create an opening for someone with my skill."
If you like the idea of "promotion from within," this company has a pretty good track record.
To me, nobody looks bad here. Not any of the people hiring, not the OP, not the friend with the insider scoop. Things work out this way. And the OP is a great job candidate!!