Skip to content

Commerzbank photoTAN: current TAN mechanism remains 999 while 2-step mechanism is 900, similar issue with DKB and BW-Bank #212

Open

Description

@QHLe

Describe the bug
With Commerzbank photoTAN, the client can end up in a state where the current TAN mechanism is still 999, while the bank-advertised usable two-step mechanism is 900.

This makes the bootstrap/follow-up flow brittle. In particular, code paths such as minimal_interactive_cli_bootstrap() and is_challenge_structured() appear to assume that get_current_tan_mechanism() is always present in get_tan_mechanisms(). For this Commerzbank flow, that assumption does not always hold.

*Bank I tested this with
Name of the bank: Commerzbank
FinTS URL:https://fints.commerzbank.de/fints

Expected behavior
After dialog initialization, the client should be able to continue normally with the bank-advertised usable two-step TAN method.

In this case, once the bank reports 900 and 999 as allowed methods, the flow should be able to continue with 900 (photoTAN) without requiring application-level workarounds.

Code required to reproduce

**Describe the bug**

With Commerzbank photoTAN, the client can end up in a state where the current TAN mechanism is still `999`, while the bank-advertised usable two-step mechanism is `900`.

This makes the bootstrap/follow-up flow brittle. In particular, code paths such as `minimal_interactive_cli_bootstrap()` and `is_challenge_structured()` appear to assume that `get_current_tan_mechanism()` is always present in `get_tan_mechanisms()`. For this Commerzbank flow, that assumption does not always hold.

**Bank I tested this with*
Name of the bank: Commerzbank
FinTS URL:https://fints.commerzbank.de/fints

**Expected behavior**

After dialog initialization, the client should be able to continue normally with the bank-advertised usable two-step TAN method.

In this case, once the bank reports `900` and `999` as allowed methods, the flow should be able to continue with `900` (`photoTAN`) without requiring application-level workarounds.

**Code required to reproduce**
```python
import os
from fints.client import FinTS3PinTanClient, NeedTANResponse
from fints.utils import minimal_interactive_cli_bootstrap

client = FinTS3PinTanClient(
    os.environ["FINTS_BLZ"],
    os.environ["FINTS_USER"],
    os.environ["FINTS_PIN"],
    os.environ["FINTS_SERVER"],
    customer_id=os.environ["FINTS_CUSTOMER_ID"],
    product_id=os.environ["FINTS_PRODUCT_ID"],
    product_version=os.environ["FINTS_PRODUCT_VERSION"],
)

client.set_product(
    os.environ["FINTS_PRODUCT_NAME"],
    os.environ["FINTS_PRODUCT_VERSION"],
)

minimal_interactive_cli_bootstrap(client)

with client:
    if isinstance(client.init_tan_response, NeedTANResponse):
        print(client.init_tan_response.challenge)
        tan = input("TAN: ").strip()
        client.send_tan(client.init_tan_response, tan)

    print("current TAN mechanism:", client.get_current_tan_mechanism())
    print("known TAN mechanisms:", list((client.get_tan_mechanisms() or {}).keys()))
    print(client.get_sepa_accounts())

Log output / error message
WARNING:fints.client:Dialog response: 3920 - Zugelassene Ein- und Zwei-Schritt-Verfahren für den Benutzer. (['900', '999'])
TAN bestaetigt.
System-ID:
Bankseitiger Benutzer:
Aktuelle TAN-Methode: 900
Verfuegbare TAN-Methoden:
{'code': '900', 'name': 'photoTAN'}

Additional context
What worked for me as a workaround was:

initialize the dialog normally
allow the client to start with current mechanism 999
after dialog initialization, explicitly switch to the first real two-step method (900)
continue with the photoTAN challenge
After doing that, dialog initialization and SEPA account retrieval worked.

Activity

  1. changed the title [-]Commerzbank photoTAN: current TAN mechanism remains `999` while 2-step mechanism is `900`[/-] [+]Commerzbank photoTAN: current TAN mechanism remains `999` while 2-step mechanism is `900`, similar issue with DKB and BW-Bank[/+] on Mar 30, 2026
  2. raphaelm commented on Jun 2, 2026

    @raphaelm
    Owner

    I don't have a Commerzbank account, so won't be able to debug this

  3. gagam3hl commented on Nov 27, 2026

    @gagam3hl

    We run python-fints 5.0.1 in production against Commerzbank (https://fints.commerzbank.de/fints, photoTAN) and get the same response:

    3920 - Zugelassene Ein- und Zwei-Schritt-Verfahren für den Benutzer. (['900', '999'])
    

    Root cause: fetch_tan_mechanisms() sets '999' as a placeholder before the sync dialog. When the 3920 arrives, _process_response() only picks a two-step method if the current function is None or missing from allowed_security_functions. Commerzbank lists '999' as allowed, so the placeholder is taken as a real choice and the client stays at '999'. After that, minimal_interactive_cli_bootstrap() treats '999' as already chosen and never offers 900. is_challenge_structured() then fails with KeyError: '999', because '999' has no HITANS entry. DKB and BW-Bank presumably also list '999' next to their two-step method, which would explain the same behaviour there.

    Workaround until a fix is released: pick the method yourself after fetch_tan_mechanisms() and before opening the dialog. Switching after dialog init can raise Cannot change TAN mechanism with a standing dialog.

    client.fetch_tan_mechanisms()
    mechanisms = client.get_tan_mechanisms()
    two_step = [f for f, m in mechanisms.items() if f != '999' and m.tan_process == '2']
    if two_step:
        client.set_tan_mechanism(two_step[0])  # Commerzbank: '900' (photoTAN)
    minimal_interactive_cli_bootstrap(client)  # now only asks for the TAN medium
    with client:
        ...

    Fix: #232 treats '999' like "not chosen yet" in both places. It includes a regression test that fails without the fix. If the bank allows only '999', the client still falls back to it. @raphaelm, since you don't have a Commerzbank account: the test reproduces the 3920 response against the existing mock server, so no account is needed to verify it.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions