Site AI Auditby Internet Solutions

Session Hijacking and Fixation: Protect Logged-In Users

20 tháng 10, 20268 phút đọcBảo mật & SSL
Session Hijacking and Fixation: Protect Logged-In Users

Short answer: After you log in, a website recognises you by a session identifier, usually stored in a cookie. If an attacker steals that identifier, or tricks the site into using one the attacker already knows, they can act as you without a password. The defences are well known: use HTTPS everywhere, set cookie flags, create a new session ID at login, set sensible timeouts and add a second login factor.

What a session is

The web has no built-in memory. Each request is separate, so the server cannot tell by itself that two requests came from the same person. To solve this, a site gives you a session identifier when you log in. Your browser sends it back with every request, and the server looks it up and recognises you.

That identifier works like a temporary key. While it is valid, whoever presents it is treated as the logged-in user. The password is checked only once, at login. Afterwards the key does the work. This is why protecting session identifiers is as important as protecting passwords.

WordPress works in a similar way, using authentication cookies that prove who you are for a limited time. Other applications use session cookies, tokens or both.

How session hijacking works

Session hijacking means that an attacker obtains a valid session identifier belonging to someone else and uses it. The main routes are:

Once the attacker has the identifier, they paste it into their own browser. The website sees a valid session and treats the attacker as the user, with the same rights. If the victim is an administrator, the damage can be large.

How session fixation works

Fixation reverses the order. Instead of stealing an identifier after login, the attacker plants one before it. The attacker first obtains a valid but anonymous session ID from the site. Then they make the victim use that same ID, for instance through a crafted link or by setting a cookie from a related site.

The victim logs in. If the application keeps the same identifier after login, that identifier is now attached to a logged-in user, and the attacker already knows it. The attacker simply uses it and is logged in as the victim.

The fix is a rule every login system should follow: always create a new session identifier at login and whenever the user’s privilege level changes. A planted ID then becomes useless the moment the victim logs in.

Cookie flags that make theft harder

Cookies carry flags that control how browsers handle them. Three of them matter for sessions:

  1. HttpOnly. Scripts on the page cannot read the cookie. This blocks the most common XSS theft method.
  2. Secure. The browser sends the cookie only over HTTPS, never over plain HTTP.
  3. SameSite. Limits when the cookie is sent in requests started from other sites, which reduces cross-site request attacks. Read more in secure cookie flags and CSRF attacks explained.

These flags do not remove the need to fix the underlying flaws, but they raise the cost of an attack considerably.

HTTPS everywhere and HSTS

A session cookie that travels over plain HTTP can be read by anyone on the path. The fix is to serve the entire site over HTTPS, not only the login page. Redirect every HTTP request to HTTPS and avoid mixed content. Then add the HSTS header, which tells browsers to use HTTPS for your domain without trying HTTP first. See our guide to the HSTS header for the steps and risks.

Without HSTS, a first request over HTTP can still be intercepted before the redirect happens. With HSTS, browsers remember the rule, which closes that gap for returning visitors.

Timeouts, logout and session management

Even a protected session should not live forever. Good session management includes:

Do not tie a session strictly to an IP address. Mobile users change networks constantly, and this causes false logouts. Device and behaviour signals are more flexible.

What to do on a WordPress site

WordPress offers several useful tools for session security:

Signs that a session has been hijacked

Hijacking is quiet by design. Possible signs include logins from unfamiliar places or devices, changes in settings that nobody remembers making, new administrator accounts and sudden changes to content. A security log with timestamps, IP addresses and user agents makes these visible. If you suspect hijacking, end all sessions, change passwords, rotate the secret keys and look for the original weakness, such as an injected script or a vulnerable plugin.

Developers building custom login systems should treat session handling as a feature that is easy to get wrong. Use the session mechanism of a mature framework instead of writing your own, store only a random identifier in the cookie and keep all other data on the server. Make identifiers long and unpredictable, never put them in web addresses, and delete them from the server when they expire. Log the creation and end of sessions so that suspicious patterns can be investigated later.

For ordinary visitors, a few habits reduce the risk. Avoid logging in to important accounts on public Wi-Fi without a trusted connection, log out of shared computers, keep the browser and operating system up to date and be careful with browser extensions, because a malicious extension can read cookies. If you manage a website for a team, remind everyone to use a password manager and two-factor login and to log out of the admin area on devices that others can reach.

If you ever suspect that an account has been taken over, act in a fixed order: end all sessions, change the password, check for changes made by the intruder, rotate keys and review the site for the weakness that allowed it. Doing the steps in this order stops the attacker first and then cleans up.

What Site AI Audit can and cannot tell you

Site AI Audit checks the public side of these protections: the SSL certificate and its expiry, the redirect from HTTP to HTTPS, security headers and exposed software versions. It does not log in to your site, so it cannot inspect session handling or cookie behaviour behind the login. It helps you confirm that the basic transport protection is in place. You can run a free check of your website or see the plans.

Related reading

The bottom line

A session ID is a key that works without a password. Keep it from being stolen with HTTPS, HttpOnly and Secure cookies and by fixing XSS. Keep it from being planted by issuing a new ID at login. Limit its lifetime, and add two-factor login for accounts that matter.

FAQ

What is the difference between hijacking and fixation?

Hijacking steals a session ID after the user has logged in. Fixation plants a known ID before login and waits for the victim to authenticate with it. The defences overlap, but a new ID at login stops fixation specifically.

Does two-factor authentication stop session hijacking?

Not directly, because the stolen cookie already represents a completed login. It does protect the login itself and limits other attacks, so use it together with cookie protection.

Is it enough to use HTTPS on the login page only?

No. The session cookie is sent with every request, so every page must use HTTPS. Otherwise the cookie can be read on any page loaded over plain HTTP.

How do I log everyone out of my WordPress site?

Change the secret keys and salts in the configuration file. All existing login cookies become invalid and every user must log in again.

Can antivirus software prevent cookie theft?

It can help against malware on a device, but it cannot fix a vulnerable website. Protect the site with updates, headers and secure cookie settings as well.

#Web vulnerabilities#Website security#WordPress security
Hãy kiểm tra website của chính bạn — miễn phí.Website của bạn cần sửa gì — và nên bắt đầu từ đâu.
Bắt đầu miễn phí
Internet Solutions

Sản phẩm khác từ đội ngũ chúng tôi

Do Internet Solutions phát triển. Hãy thử các sản phẩm khác của chúng tôi — mỗi sản phẩm giúp bạn tiết kiệm thời gian theo một cách riêng.

internet-solutions.net ↗
01Tự động đăng mạng xã hội
PostRSS

Bài mới từ nguồn cấp RSS của bạn được tự động đăng lên Facebook, X, LinkedIn, Telegram và hơn 60 mạng khác.

Gói miễn phí · từ 2014Truy cập →
02Chat trực tuyến AI cho website
Talkmio

Website của bạn trả lời khách truy cập 24/7 từ chính nội dung của bạn, bằng ngôn ngữ của họ.

Gói miễn phí · không cần thẻTruy cập →
03Trợ lý AI
Ask Mio

Trò chuyện, viết code, thiết kế, viết bài và nghiên cứu. Mio chọn mô hình tốt nhất cho từng việc.

Gói miễn phíTruy cập →
04Lái tự động AI cho blog và mạng xã hội
AI Blog Autopilot

AI viết bài SEO dài 2.000–3.000 từ và chia sẻ từng bài lên hơn 60 mạng xã hội.

3 bài đầu tiên miễn phíTruy cập →
05Thu thập SEO chuyên sâu
Site SEO AI Audit

Thu thập SEO toàn diện trên 7 lĩnh vực, gồm cả khả năng hiển thị trong tìm kiếm AI, với cách sửa xếp theo mức tác động.

Lần kiểm tra đầu tiên miễn phíTruy cập →
06Nguồn cấp RSS và sản phẩm
RSS Feed Creator

Tạo RSS từ bất kỳ trang web nào, cùng nguồn cấp sản phẩm cho Google và Meta tự động cập nhật.

Gói miễn phíTruy cập →
07Phát triển website và SEO
Internet Solutions

Website, cửa hàng trực tuyến và hệ thống theo yêu cầu, do đội ngũ của chúng tôi thiết kế, xây dựng và vận hành.

Từ 2011Truy cập →