It's a common scenario
Four people inside of one car. Car gets pulled over. There is one bag of marijuana inside of the car. All four people get charged with possession of marijuana.
This is known as constructive possession, and yes, it's legal. Everybody in and around an area where marijuana is found can be charged with constructively possessing that marijuana provided the marijuana is close enough so that all could exercise dominion over the marijuana, and all of the people have knowledge that the marijuana is present.
So constructive possession requires the state to prove that you were in a position to exercise dominion over the marijuana (close enough to it), and that you had knowledge of the presence of the marijuana. The state must prove those two things.
While it is possible to be near marijuana (you're a passenger in your friend's car and the marijuana is in the glove box), you might not know it's there. Unfortunately, if your friend doesn't fess up and tell the cop it's their's, both of you can be charged.
But the state must prove that you had knowledge of the presence of the marijuana. Knowledge is often proven through statements that an accused person will make to police. So under no circumstances should you tell a police officer that you were aware of the presence of marijuana if suspected of constructive possession. You never have a duty to speak to police, so exercise your right and keep quiet. It can only help you in the end.
Constructive possession doesn't just exist with regard to marijuana possession. You can be accused of constructively possessing any controlled substance.
Constructive possession cases can be defensible because it is reasonable - under many circumstances - that the accused had no idea that the drugs were present. If you don't make a statement, the state will have a hard time proving the element of knowledge.