Anytime you have a fire on an engine it is a safety problem due to the gasoline tank on the machine. A fire is not easily extinguished if the gas tank ignites and could catch other things on fire around the lawn mower.
With that being said, it is finding out why it is backfiring that is the most important part of this problem. In order for a backfire to occur through the air filter box, the intake valve must be open while the spark plug is igniting the mixture. The intake valve could have some carbon buildup under the valve seat or it could be hanging open because the valve guide is causing it to stick.
Another possibility is that the ignition timing is not correct. If the lawn mower blade has contacted something such as a root and this is a push mower, the flywheel key may be partially sheared and cause the timing to be incorrect. It is also possible that the timing gear has damage to it.
All of these items should be checked out to determine which is causing the problem and eliminate them one by one.