As it stands, more than 40 million Americans are racking up $2,726 in student loan debt every second. Aside from the clear financial challenges that come with this type of debt, there are also important legal and tax implications to be aware of—especially for those who are participating in loan forgiveness programs or are in default.

To avoid a real headache, it’s crucial to know your rights and understand the law surrounding student loans. Below are some of the biggest considerations for anyone in student loan debt, plus how to keep yourself in the law’s good graces.

1. Student Loan Forgiveness Can Leave You with a Huge Tax Bill

Income-driven repayment programs such as Income-Based Repayment (IBR) and Pay As You Earn (PAYE) can make life easier for people who are struggling to afford their monthly payments. Although these government-backed repayment programs each work differently, they all culminate in total student loan forgiveness at the end of the repayment period.

Still, this is one area where the devil is in the details. In most cases (but not all), the IRS requires you to pay income taxes on the entire forgiven balance the year your debt was wiped away.

If you’re not prepared to pay these taxes, you could wind up in a world of hurt—and in trouble with the tax man. Of course, the best way to prepare yourself for these taxes is to speak with a tax professional about what to expect and how to ensure that you have the funds when that bill comes.

2. Defaulting on Your Student Loans Is Bad News for Your Finances

New analysis from The Wall Street Journal shows that as many as 40% of student borrowers are in some stage of default on their loans. In many cases, borrowers might look to fix this situation and get on a payment plan in the future. But for those who choose to ignore their loans altogether, the consequences can be dire.

For example, letting your loans fall into default not only prevents you from joining certain loan forgiveness plans, but it will wreck your credit too. That means if you ever want to take out another type of loan—such as a car loan or mortgage—you’ll face sky-high interest rates, or you might not qualify at all. Plus, you’ll accrue collection fees and may even have your wages garnished or your tax refund withheld.

All of these issues can lead to legal implications galore, but can easily be avoided by keeping your loans in good standing.

3. You Can Be Sued for Ignoring Your Student Loans

Some debtors simply don’t care about taxes or wage garnishments, taking a laissez-faire attitude toward student loan default.

But the mountain of consequences doesn’t end at your paycheck and credit score. Although few people know this—and it’s rather rare—private lenders can actually sue you if you ignore your defaulted student loans and do nothing to fix the situation. In fact, the Associated Press reported that thousands of lawsuits have been filed by private student loan lenders against borrowers in default since 2013. Talk about a bad day.

4. You Shouldn’t Count on Bankruptcy to Get Student Loans Discharged

Many borrowers who are struggling under a mountain of debt seek out legal help. Often, the last-resort solution is filing for bankruptcy. When it comes to bankruptcy and student loans in particular, however, the way out isn’t quite that simple.

The prevailing myth is that it’s impossible to have student loans discharged in Chapter 7 bankruptcy. It is in fact possible, though the chances are pretty slim. In order to successfully have your slate wiped clean, you have to prove extreme financial hardship and file a Complaint to Determine Dischargeability.

Getting student loans discharged in bankruptcy isn’t impossible, but it certainly isn’t easy. Rather than counting on bankruptcy as a way out, explore other options to make that debt manageable by getting on an income-driven plan or pursuing a forgiveness program such as PSLF.

5. Phony Student Loan Relief Companies Want Your Money

Another legal consideration that comes into play with student loans is the number of scams currently in the works. From the phony Obama Student Loan Forgiveness Program to the many predatory offers for debt relief that keep circulating, the companies that hope to get a piece of your net worth are plentiful.

As the Secretary of Education said in a press release, “Many debt relief companies charge exorbitant fees for these services and often solicit unsuspecting borrowers online and through mobile ads, social media, phone calls—and even mail sent to your home.”

One golden rule to follow is this: If it seems far too good to be true, it probably is.

Final thoughts: Our addiction to debt—and particularly student loan debt—has created several financial situations where legal issues and tax problems come into play. To avoid any negative consequences, make sure to stay current on your student loans and learn as much as you can about how legitimate government-sponsored programs work. With student loans, what you don’t know can hurt you.