[Web] fix add/time_limited_alias silently discarding requests and validity#7345
Open
smpaz7467 wants to merge 1 commit into
Open
[Web] fix add/time_limited_alias silently discarding requests and validity#7345smpaz7467 wants to merge 1 commit into
smpaz7467 wants to merge 1 commit into
Conversation
…idity Three defects in add/time_limited_alias: The description was read as $_data['description'] without a guard. When a client omits it, null is bound to spamalias.description, which is TEXT NOT NULL, so the insert raises a PDOException. The global exception handler is terminal, so process_add_return() never echoes anything and the caller sees HTTP 200 with an empty body while no alias was created. Default it to an empty string instead. The validity guard used a single condition whose else branch also caught the success case, so every valid validity was overwritten with the 8760 hour default and the parameter did nothing. Only invalid values were rejected. Nest the range check so a valid value survives. The OpenAPI spec documented only username and domain, while the code also reads description, validity and permanent. Spec driven clients therefore could not construct a working request. Document all three. spamalias.description is the only NOT NULL description column in the schema, which is why the same unguarded read in add/domain and add/resource does not fail, both of those columns are nullable. This does not change the generic exception handling. A database error is still swallowed into an empty HTTP 200, and the message the handler builds carries the raw PDOException, so surfacing it to API clients would need sanitising first. That is left for a separate change. Refs mailcow#7287 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Three defects in
POST /api/v1/add/time_limited_alias.1. A request without
descriptionis silently discarded (the reported bug)descriptionwas read as$_data['description']with no guard. When a client omitsit,
nullis bound tospamalias.description, which isTEXT NOT NULL, so theinsert raises a
PDOException.set_exception_handler()is terminal — PHP tears down the script once thehandler returns — so
process_add_return()never runs and nothing is ever echoed.The client gets
HTTP 200with an empty body, and no alias exists. Defaulting thefield to an empty string removes the null insert.
spamalias.descriptionis the onlyNOT NULLdescription column in the schema,which is why the same unguarded read in
add/domainandadd/resourcedoesn'tfail — both of those columns are nullable.
2.
validitynever workedWhen
validityis present and valid,!filter_var(...)isfalse, so thecondition is false and the
elsefires — overwriting the user's value with thedefault. Only invalid values were rejected; every valid one was discarded:
241876000/87601/-5/"abc"Nesting the range check fixes it. I'd have had to leave
validityout of the specotherwise — documenting a parameter that provably does nothing seemed worse than
leaving it undocumented.
3. Spec gap
The spec documented only
usernameanddomain, while the code readsdescription,validityandpermanenttoo, so spec-driven clients (Swagger UI,python-mailcow, generated SDKs) could not construct a working request. All threeare now documented.
Verification
php -lclean;openapi.yamlparses and exposes all five properties.spamaliasDDL and thesql_modefrom the issue:description = NULL→ERROR 1048 (23000): Column 'description' cannot be nulldescription = ''→ insert succeeds, row createdNot addressed
The generic error handling. A DB error is still swallowed into an empty
HTTP 200for every endpoint, which is the second defect in the issue. Fixing it properly is
more than a bugfix: the handler builds
array('mysql_error', $e)from the rawPDOException, which carries the SQL statement and schema details, so echoing it toAPI clients would turn a silent failure into an information disclosure. That needs
sanitising plus a decision on the status-code contract — a maintainer call, so I've
left the issue open rather than closing it.
Refs #7287