Skip to content

Generated XEP-0388 encoders serialize child elements in schema-invalid order #4606

Open

Description

@rallep71

The generated XEP-0388 codec serializes several child elements in an order that does not match the
XEP-0388 schema. The underlying causes are a reference-ordering problem in the fast_xml generator
and an incorrect sasl2_continue declaration order in xmpp/specs/xmpp_codec.spec.

thx

Activity

  1. badlop commented on Aug 24, 2026

    @badlop
    Member

    Nice finding! Can you mention what's the ordering problem in fast_xml and the incorrect declaration order in the xmpp library?

  2. rallep71 commented on Aug 24, 2026

    @rallep71
    Author

    Hi, if I manage to get round to it today, I’ll put together a more detailed explanation. It’s also linked to the bug I’ve reported – though it isn’t public yet; prefix is looking into it. You could always enquire about it. It should get the go-ahead from you lot first.

  3. rallep71 commented on Aug 24, 2026

    @rallep71
    Author

    Here are the details.

    The first problem is in fxml_gen:group_refs/1. It groups references in a dict
    and returns them through dict:to_list/1, so the declaration order from
    #elem.refs is lost. make_elem_enc_fun/5 then folds over that result and reverses
    the accumulator. The generated sibling order therefore depends on the dict
    order instead of the order declared in the codec specification.

    With the current generated xep0388.erl this results in, for example:

    authentication: inline before mechanism
    success: authorization-identifier before additional-data
    continue: text, tasks, additional-data

    XEP-0388 requires:

    mechanism(s), then inline
    additional-data, then authorization-identifier
    additional-data, tasks, text

    The second issue is independent of that generator problem:
    sasl2_continue in specs/xmpp_codec.spec currently declares additional-data,
    text, tasks. It should declare additional-data, tasks, text.

    The source fix should be made in fast_xml and xmpp_codec.spec, followed by
    regeneration. Editing generated xep0388.erl alone would only hide the problem.

    processone/fast_xml#53 processone/xmpp#112 thx

  4. prefiks commented on Aug 25, 2026

    @prefiks
    Member

    Looking at those linked pull requests, those changes make sense. This will likely change order inside other stanzas as well, which i don't think this will change handling in ejabberd, but it may possibly be issue in test suite if some tests aren't using xmpp decoder, and are comparing to raw data that could be changed by this.

  5. rallep71 commented on Aug 25, 2026

    @rallep71
    Author

    Hello and thank you for your reply,

    I only realised this whilst integrating and debugging SASL2 and Bind2 into the XMPP client.
    I hadn’t considered that this might cause problems with other dependencies in the test suite.
    What do you suggest? Right, I’ll look into it a bit more deeply to see how these proposed changes might affect other parts of the system.

  6. prefiks commented on Aug 25, 2026

    @prefiks
    Member

    Don't worry about this, we will just fix tests when this happen, i just left that as a note to myself or badlop when this will be merged

  7. badlop commented on Aug 25, 2026

    @badlop
    Member

    As the fixes are already available in rallep library forks, I'll use them in my ejabberd fork to run the tests, and check if ejabberd tests need some update before merging :)

  8. self-assigned this
    on Aug 25, 2026
  9. badlop commented on Aug 27, 2026

    @badlop
    Member

    Right, the fixes in fast_xml produce several changes in xmpp when running "make spec xdata".

    The good news: ejabberd passes all tests after applying fast_xml and xmpp patches

    Just a small note:

    The source fix should be made in fast_xml and xmpp_codec.spec, followed by regeneration.

    It would be great if you can split your fast_xml commit into two:

    1. First commit including your manual changes, the ones that you made yourself
    2. Second commit with the automatic result of regeneration, something like "Result of running make spec" or whatever
  10. rallep71 commented on Aug 27, 2026

    @rallep71
    Author

    Good to hear that ejabberd passes the full test suite with both patches applied.

    Yes, that split makes sense. I’ll update processone/fast_xml#53 so the first commit contains the hand-written generator and regression-test changes, while the second contains only the regenerated src/fxmlrpc_codec.erl. I’ll note REBAR=rebar3 make spec as the regeneration command.

  11. rallep71 commented on Aug 27, 2026

    @rallep71
    Author

    It’s sorted, but my status is still showing as ‘pending’,

  12. badlop commented on Aug 28, 2026

    @badlop
    Member

    All is merged and tests are passed... I mean the tests that cover 35% of ejabberd source code. The next ejabberd release notes should mention this fix, in case there is somewhere some code that depends on the previous order.

    Something like this, does it look correct?


    Fixed the ordering of some XML child elements

    There was a reference-ordering problem in the fast_xml generator, it generated XML encoders that could reorder child elements in a different order from the one declared in the codec specification. From now, the order is the one declared in the codec specification. See details in processone/fast_xml#53

    Additionally there was an incorrect sasl2_continue declaration order in the xmpp erlang library: it declared "additional-data, text, tasks". Now it follows the ordering defined in XEP-0388 schema: "additional-data, tasks, text". See details in processone/xmpp#112

    Acknowledgments

    • rallep71 for the fixes in fast_xml and xmpp XML child ordering
  13. added this to the ejabberd 26.xx milestone on Aug 28, 2026
  14. rallep71 commented on Aug 28, 2026

    @rallep71
    Author

    Yes, that looks good to me. It describes both parts of the fix correctly, and mentioning it in the release notes makes sense
    in case anything relied on the old generated order. The acknowledgement is fine too. Thanks for merging both changes and
    running the ejabberd tests.

    THX

  15. dwd commented on Aug 29, 2026

    @dwd

    Erm... I think I probably wrote the XEP-0388 schema, and I'm not entirely sure why I made it a sequence and not xs:all. Quite possibly I just used xs:sequence because I knew about it.

    Is there any reason, we think, that the ordering actually makes a difference here?

    Put another way, if we changed the schema to remove the ordering requirement, would this be a problem?

    (I'll raise this to the XSF's Standards SIG too)

  16. rallep71 commented on Aug 29, 2026

    @rallep71
    Author

    From my side, I found that the generated encoders did not preserve the order declared in the codec specification. I did not
    establish that SASL2 itself depends on that order, or that clients reject a different order.

    If the Standards SIG concludes that the child order is not significant, I would have no objection to relaxing the schema. I
    would still keep the fast_xml change, as the generator should behave deterministically and follow the codec specification it
    is given.

    Thanks for taking this to the Standards SIG.

  17. badlop commented on Sep 24, 2026

    @badlop
    Member

    What's the status of the XEP modification?

    Is the change in processone/xmpp#112 relevant, or maybe it should be reverted before next xmpp/ejabberd releases?

  18. rallep71 commented on Sep 25, 2026

    @rallep71
    Author

    Hmm, there haven’t been any changes to the standard yet: “Version
    1.0.4 (25 August 2025)”. I’ll stick to my proposed changes; whether they’ll be incorporated into the next version of ejabberd is up to processone to decide, and as long as there are no changes to the standard, it simply remains the standard. Anyway.

    For my part, I’ve put the implementation on hold for the time being until this has been clarified; this also applies to another fix I’ve submitted, which I won’t go into here. On top of that, it’s not just ejabberd that’s affected – Prosody has similar issues – but I won’t submit the fixes there until everything here has been sorted out.

  19. dwd commented on Sep 25, 2026

    @dwd

    Yeah, sorry, I've not made a PR yet. But I'll try to get that sorted today, and through council next week?

  20. tmolitor-stud-tu commented on Oct 1, 2026

    @tmolitor-stud-tu

    Erm... I think I probably wrote the XEP-0388 schema, and I'm not entirely sure why I made it a sequence and not xs:all. Quite possibly I just used xs:sequence because I knew about it.

    Is there any reason, we think, that the ordering actually makes a difference here?

    Put another way, if we changed the schema to remove the ordering requirement, would this be a problem?

    (I'll raise this to the XSF's Standards SIG too)

    @dwd no, I don't think that should be a problem and in fact it could also be that the ordering in the schema comes from me :D

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions