Well... I can't comment on legality. That depends on where you live. I have stored gas cans in my garage. One or two. To my knowledge I can store gas anywhere I want to on my property. Do your own research on that.
As far as safety, I'd say do your own research. Many factors to consider. I mean your car probably has 15-20 gallon tank. Its more about the cans. If my garage wasn't connected to my house that would change things. I store my in a shed because it makes sense storage wise/space and I don't need access to it all the time.