Skip to content

[BUG] HTTP 402 for Mega #150

Closed
Closed

Description

@BrandonStudio

Please confirm the following

  • I confirm my description is clear and polite, that I have provided the necessary diagnostic information, and that this is reproducible on the latest version.
  • I confirm I have checked the relevant documentation and existing issues / discussions, and this report is not a duplicate.
  • I confirm this is an issue with the Worker project, not caused by network or user error, and not an issue specific to the Go version.
  • I confirm I have read the open-source license / disclaimers / usage policy, and understand that I bear all risks of use.

Version (required)

No response

Platform (required)

Cloudflare Workers

DB_FORMAT (required)

map (single JSON blob)

DB_DRIVER (required)

auto

Storage Driver (required)

Mega

Bug Description (required)

Mega API HTTP error: 402

Error Information (required)

This thread may be helpful:
qgustavor/mega#239 (comment)

Relevant Configuration (required)

Irrelavent

Reproduction Link (optional)

No response

Activity

  1. PIKACHUIM commented on Nov 2, 2026

    @PIKACHUIM
    Member

    Please try #166

    Wait your feedback

  2. BrandonStudio commented on Nov 3, 2026

    @BrandonStudio
    Author

    Mega authentication failed: -9
    No relavent log captured

  3. added a commit that references this issue on Nov 9, 2026
    d285310
  4. PIKACHUIM commented on Nov 9, 2026

    @PIKACHUIM
    Member

    Please retry #166
    I tested on cf worker, it works but a little bit slow :(

  5. PIKACHUIM commented on Nov 9, 2026

    @PIKACHUIM
    Member

    "Mega authentication failed: -9" means your account has been blocked, and you may need to allow login or input 2FA Code

  6. BrandonStudio commented on Nov 10, 2026

    @BrandonStudio
    Author

    OK now. But 503 sometimes.

    Fundamentally, I doubt whether this is the right way. As these PoW things take a lot of CPU time on serverless worker, while the worker could have returned very early just dealing with API calls. So I wonder that is it possible to move the PoW computes elsewhere, for example, moving to a client browser? Could there be a mechanism supporting this?

  7. BrandonStudio commented on Nov 10, 2026

    @BrandonStudio
    Author

    A comparison:
    normal requests of this project take 2-5 CPU time, whereas the fs/list with Mega PoW takes 1837 CPU time

  8. PIKACHUIM commented on Nov 10, 2026

    @PIKACHUIM
    Member

    The 503 was caused by rate limiting due to Mega, and this issue has just been fixed.
    POW is not suitable for frontend processing because the direct download scenario needs to be taken into account.

    The recent push made the following changes:

    1. Retry on 503: attempt a retry when a 503 occurs.
    2. Persist the SID: minimize authentication during cold starts as much as possible (to reduce 503s).
    3. Reduce the number of encryption operations.
  9. PIKACHUIM commented on Nov 10, 2026

    @PIKACHUIM
    Member

    However, since the first login always requires POW verification, and the CF free plan only supports 10ms of CPU time, there is a certain probability that 5xx errors will occur. But theoretically, once you have logged in successfully once, there is no need to repeatedly verify the POW.

  10. BrandonStudio commented on Nov 10, 2026

    @BrandonStudio
    Author

    My Mega account was blocked just now... saying that unauthorized third party login detected

    Now it's fine, 8ms for fs/list.

    Since PoW only happens when first logging in, I'm wondering that could there be a protocol that the first time PoW should be done together with the front end and the client browser, later API calls could then process?

  11. PIKACHUIM commented on Nov 10, 2026

    @PIKACHUIM
    Member

    You can use the email link to reset your password, which will unlock your account.
    However, because the Cloudflare IP is used by a very large number of users, it is quite "dirty," so encountering this situation is very common.

    Computing POW on the frontend is a fairly large undertaking, and for a case where it only needs to be computed once, it's not really recommended to implement it.
    But I'll consider whether to add the option of using api.oplist.org to generate credentials on the frontend and then fill them into the worker instance — this feature isn't available yet

    The PR will be merged and this issue will be closed. If you have any further questions, please open a new issue.

  12. BrandonStudio commented on Nov 10, 2026

    @BrandonStudio
    Author

    But I'll consider whether to add the option of using api.oplist.org to generate credentials on the frontend and then fill them into the worker instance — this feature isn't available yet

    Could you talk a little bit more about this? How would this work?

  13. BrandonStudio commented on Nov 10, 2026

    @BrandonStudio
    Author

    BTW, is this PoW feature implemented on the Go version?

  14. PIKACHUIM commented on Nov 10, 2026

    @PIKACHUIM
    Member

    Yes, the Go version does implement POW verification for this cloud drive.

    Regarding POW verification on the API site (api.oplist.org), its principle is the same as what you described — except it's implemented not on the worker's frontend but on the frontend of the credential request site. If possible, the data should not be sent to the backend and would be processed entirely on the frontend.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions