My apartment is in foreclosure and the owner has talked about bankruptcy. I am worried that I will not get my security deposit returned when I leave. What can I do to protect myself?
If a bank forecloses on the owner of your building, they would do that subject to your lease, and they would have to honor it. Banks don't want to be landlords anyway, so they would probably try to sell the building, and this would take some time.
If you're not on a current lease and are a month-to-month tenant, then you could be given 30 days' notice to vacate (assuming you're not in a rent-controlled building where other rules apply), and then you might be able to work something out regarding your security deposit (which is not supposed to be used for last month's rent anyway). Again, they have no reason to terminate your tenancy if you're a paying tenant.
If the owner of your building files for bankruptcy protection, then the bankruptcy trustee might be the one who has control over your tenancy and security deposit, and a bankruptcy wouldn't necessarily change your situation, since the trustee might be happy to have a paying tenant int he building until a new building owner can be found.
Both a foreclosure and a bankruptcy are likely to give you a certain amount of time to deal with things, but in both cases, you may need to contact either the foreclosing bank or the bankruptcy trustee to see what their intentions are regarding your tenancy. What you don't want to do is pay your landlord/owner rent if he's no longer the owner - then the rent belongs to the bank. You'll get notice from the bank if this happens.
Disclaimer: Please note that this answer does not constitute legal advice, and should not be relied on, since each state has different laws, each situation is fact specific, and it is impossible to evaluate a legal problem without a comprehensive consultation and review of all the facts and documents at issue. This answer does not create an attorney-client relationship.
You might want to consider when your lease is up and see if you can come to a written agreement with the current landlord that since the building is being foreclosed upon that the deposit (if the same amount) cover your last months rent.
Remember, get it in writing.
Possible make August your last month if agreeable, with your deposit being the last months rent if your landlord is going to let the property be foreclosed upon
This is one of the potentially safest solutions but not your only one. Good luck. Much depends on where the property is in foreclosure, etc.