Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a client side player name sanitation #8137

Merged
merged 3 commits into from May 30, 2015

Conversation

Mailaender
Copy link
Member

Closes #3200
Closes #3332
Closes #7739
Fixes #8031

@pchote
Copy link
Member

pchote commented May 10, 2015

This sanitization will need to be done by the server when the client connects or changes their name. If somebody sends a name with a miniyaml-breaking character then the client will crash before it gets a chance to sanitize it.

var forbiddenNames = new string[] { "Open", "Closed", "Spectator" };

var clean = dirty;
if (string.IsNullOrEmpty(dirty) || forbiddenNames.Contains(clean) || clean.Contains(" AI"))
Copy link
Member

Choose a reason for hiding this comment

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

Foo AIBar will be flagged as dirty.
Perhaps EndsWith() would be better, if we must limit this.

Copy link
Member

Choose a reason for hiding this comment

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

A simpler and more robust solution would be to check against the AI names directly.

Copy link
Member

Choose a reason for hiding this comment

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

The TD and D2K bots don't have "AI" in their names.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Fixed.

@Mailaender
Copy link
Member Author

I now also added a game server side player name sanitizing during client validation from the handshake and added a server name check as requested by @obrakmann. The rules are similar.


var clean = dirty;
if (string.IsNullOrEmpty(dirty))
clean = "";
Copy link
Member

Choose a reason for hiding this comment

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

This will probably need to have some non-empty default value (Newbie is the default player name, so probably that), otherwise the sanitation in this case doesn't really work.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be replaced by Newbie and OpenRA Game (default server name) in the functions below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait a moment, you are right. My ordering of the checks is wrong. Entering # will allow an empty name.

@Mailaender
Copy link
Member Author

Optimized it again after the function split for server name checks.

@deniz1a
Copy link
Contributor

deniz1a commented May 10, 2015

This changes LobbyUtils.cs at the same lines as #8118. Edit: Also SettingsLogic.cs.

@pchote
Copy link
Member

pchote commented May 10, 2015

The most important place to do the sanitization is LobbyLogic.IntepretCommand (the "name" handler). Please add it here too.

A more polished client-side implementation would prevent the bad characters from being entered in the text fields in the first place, and then rely on the server-side implementation to deal with any hacked clients.

@penev92
Copy link
Member

penev92 commented May 11, 2015

Also please don't forget:

[20:11:21] < penev> SanitizedPlayerName() looks ok now
[20:11:33] < penev> but I'm not convinced about the server one
[20:12:51] < penev> because SanitizedPlayerName() sanitizes the name, and then checks if the new string is empty
[20:13:04] < penev> SanitizedServerName() doesn't care if the sanitized name is empty
[20:13:33] < penev> it checks before sanitizing
[20:13:46] < penev> but if my server's name is []
[20:13:53] < penev> it will do
[20:13:57] < penev> return SanitizedName(dirty);

... which will return an empty string.

@Mailaender
Copy link
Member Author

Well spotted. Updated.

server.SendMessage("{0} is now known as {1}.".F(client.Name, s));
client.Name = s;
var sanitizedName = OpenRA.Settings.SanitizedPlayerName(s);
Log.Write("server", "Player@{0} is now known as {1}.", conn.Socket.RemoteEndPoint, sanitizedName);
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a check if the name changed really?
If I try to change abcdefg30 to abcdefg30# the # is removed and abcdefg30 is now known as abcdefg30 appears.

@abcdefg30
Copy link
Member

Otherwise 👍 / ✅

@Mailaender
Copy link
Member Author

Good idea. Done.

@penev92
Copy link
Member

penev92 commented May 30, 2015

Looks good to me. Thanks! 👍

penev92 added a commit that referenced this pull request May 30, 2015
Added a client side player name sanitation
@penev92 penev92 merged commit 3666fab into OpenRA:bleed May 30, 2015
@Mailaender Mailaender deleted the sanitize-player-name branch May 30, 2015 19:22
@penev92
Copy link
Member

penev92 commented May 30, 2015

Changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants