Skip to content

Properly escape IP in sessions table insert query - #4977

Merged
ArturKnopik merged 1 commit into
otland:masterfrom
Kuchiriel:patch-1
Oct 5, 2025
Merged

Properly escape IP in sessions table insert query#4977
ArturKnopik merged 1 commit into
otland:masterfrom
Kuchiriel:patch-1

Conversation

@Kuchiriel

Copy link
Copy Markdown
Contributor

Pull Request Prelude

Changes Proposed

This PR fixes a syntax error when inserting into the sessions table by correctly quoting and escaping the IP address passed to INET6_ATON. Previously, the IP string was concatenated directly, which could result in malformed SQL queries or potential security issues.

Changes:

  • Wrapped connection->getIP().to_string() in single quotes.
  • Escaped the IP using db.escapeString() before formatting into the SQL query.

Why it matters:

Ensures correct SQL syntax and prevents connection errors when creating session entries, particularly with IPv6 addresses.

Issues addressed: From TFS Console "[Error - mysql_real_query] Query: INSERT INTO sessions (token, account_id, ip) VALUES ('1z�i���L����Lm&', 1, INET6_ATON(::ffff:127.0.0.1))
Message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '::ffff:127.0.0.1))' at line 1"

How to test:

  • Run the server.
  • Connect with an IPv6 or IPv4 client.
  • Ensure sessions are inserted correctly into the database without causing SQL errors.

Fixed the INSERT statement into the sessions table by properly escaping the IP address passed to INET6_ATON, avoiding SQL syntax errors.
Previously, the IP was inserted without quotes, causing the query to fail.
Now, the IP is correctly wrapped in quotes and escaped using db.escapeString, ensuring compatibility with both IPv4 and IPv6 connections in the database.
@Shawak

Shawak commented Jul 27, 2025

Copy link
Copy Markdown
Contributor

Aren't we getting rid of the sessions anyways with this PR? #4967

@Kuchiriel

Kuchiriel commented Jul 27, 2025

Copy link
Copy Markdown
Contributor Author

Aren't we getting rid of the sessions anyways with this PR? #4967

I hope so I can't fix the "Malformed session key" error, I tried fixing the session db, changing useSessionKey in config.lua, nothing works. :/

@ArturKnopik ArturKnopik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested, no issues with login

@ArturKnopik
ArturKnopik merged commit f72f877 into otland:master Oct 5, 2025
@Kuchiriel

Copy link
Copy Markdown
Contributor Author

LGTM, tested, no issues with login

Have you tested with OTLand Client?

@ArturKnopik

ArturKnopik commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

LGTM, tested, no issues with login

Have you tested with OTLand Client?

Tested with cipsoft client.
WTF is Otland client?

@Kuchiriel

Copy link
Copy Markdown
Contributor Author

In short https://otland.net/forums/otclient.494/
But I´ve tested, all ok, I was just curious about open source clients connection with the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants