If Safari is not affected, you may have installed a malicious Firefox extension.
First follow the instructions on this page. If there's a Firefox extension you can't remove in the Extensions manager, see below.
Back up all data before proceeding.
Triple-click anywhere in the line below on this page to select it:
~/Library/Application Support/Mozilla
Copy the selected text to the Clipboard by pressing the key combination command-C. In the Finder, select
Go ▹ Go to Folder...
from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.
A folder should open with an item named "Mozilla" selected. Quit Firefox if it's running. Move the selected item to the Trash. Relaunch the browser and test.
If the extension is still present, repeat with this line:
/Library/Application Support/Mozilla
If this folder exists, you may be prompted for your administrator login password when making changes to it.
Some kinds of malware may insert code into the Firefox application itself. If the above steps don't solve the problem, quit Firefox, delete it from the Applications folder, and download a fresh copy directly from mozilla.org.