W/THERETURN XPURGE & STATUS fixes + cservice security hardening - #88
Open
MrIron-no wants to merge 4 commits into
Open
W/THERETURN XPURGE & STATUS fixes + cservice security hardening#88MrIron-no wants to merge 4 commits into
MrIron-no wants to merge 4 commits into
Conversation
User-supplied input was concatenated into SQL statements without escaping, allowing quote breakout. Since the DB layer uses PQexec (which permits stacked statements), this enabled arbitrary SQL. - CERTCommand: escape note, fingerprint and nick!user@host in the users_fingerprints INSERT. note is free text from the user and was the primary injectable field. - HELLOCommand: escape the e-mail address in the duplicate-address lookup. Validation permitted a single quote, so the query could be broken out of.
Both paths indexed StringTokenizer without a size check; getToken() asserts on an out-of-range subscript, aborting the whole process. - SASL SCRAM client-first: a "n=" attribute with an empty value produced a zero-token tokenizer, and st3[0] aborted before the username-empty check. This is reachable pre-auth from a connecting user's AUTHENTICATE data. Guard st3 before indexing; an empty value now falls through to the existing "missing username" error path. - doXROplist: st[1]/st[2] were read before any size check (a 2-token OPLIST reply aborted), and the guard only required 6 tokens while the body reads up to st[8]. Check size >= 3 before the "NO" test and size >= 9 before the field extraction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes for the W/THERETURN
XPURGE/STATUSintegration, plus a set ofmod.cservicesecurity hardening changes (SQL injection and crashes onmalformed input) found while working on this branch.
W / THERETURN integration
PURGEsubcommand toXPURGE. The dispatch checkand the user-facing help text (
/msg X W XPURGE <#chan> -f) were stillusing the old
PURGEname after a merge; the command was effectivelyunreachable under its intended name.
cant_find_on_channotice format expects a channel name, but only theW nickname was passed, so the second
%shad no argument.shown only when
THERETURN_INTEGRATIONis enabled or the requestinguser is an admin (level >= 750), instead of to everyone.
Security fixes (mod.cservice)
SQL injection
The DB layer uses
PQexec, which permits stacked statements, so anunescaped quote in a query field allows arbitrary SQL. Fixed by wrapping
the affected user-supplied fields in
escapeSQLChars():note(andfingerprint/nick!user@host) went into theusers_fingerprintsINSERT unescaped.notewas reachable by any authenticated user, e.g.CERT ADD <valid-fp> x','y'); DROP TABLE ...; --.unescaped; validation permitted a single quote, so the string could be
broken out of. (Compiled out by default via
#undef ALLOW_HELLO, butfixed regardless.)
Crashes on malformed input
Asserts are compiled in, and
StringTokenizer::getTokenasserts on anout-of-range subscript, aborting the whole process. Two paths indexed a
tokenizer without a sufficient size check:
n=attribute with an empty valueproduced a zero-token tokenizer, and
st3[0]aborted before theusername-empty check. Reachable pre-auth from a connecting user's
AUTHENTICATEdata. Now guarded; an empty value falls through to theexisting "missing username" error path.
doXROplist—st[1]/st[2]were read before any size check (a2-token
OPLISTreply aborted), and the guard only required 6 tokenswhile the body reads up to
st[8]. Now checkssize >= 3before theNOtest andsize >= 9before field extraction.Testing
makeclean onmod.cservice.StringTokenizer: thepreviously-aborting inputs (
n=,n=) now yield an empty username(handled by the existing error path), while normal tokens still parse.