Skip to content

flutter gen-l10n does not validate placeholder type, allowing code injection into generated Dart from .arb files #192130

Closed

Description

@Badranh

Steps to reproduce

  1. Create a new app: flutter create bug
  2. Enable generation in pubspec.yaml (flutter: generate: true) and add an
    l10n.yaml + lib/l10n/app_en.arb as per the standard localization setup.
  3. In app_en.arb, set a placeholder's type attribute to a crafted string
    that closes the generated method and injects a new member (see Code sample).
  4. Run flutter gen-l10n.
  5. Inspect the generated app_localizations_en.dart.
  6. Run dart analyze on the generated output.

Reproduced on Flutter web and on a physical device (Pixel 6a, Android 16).

Expected results

flutter gen-l10n should validate the placeholder type attribute the same
way it already validates resource names (which are checked against
_isValidGetterAndMethodName). An illegal type value should raise an
L10nException and fail generation, rather than being written into source.

Ideally the supported types would be allowlisted (String, int, double, num,
DateTime, Object, plus the documented numeric/date format types).

Actual results

The placeholder type is read as a raw, unchecked string
(gen_l10n_types.dart:235) and interpolated into the generated method
signature (gen_l10n.dart:130, generateMethodParameters). A crafted type
string closes the generated method early, injects arbitrary members, and
reopens a declaration to absorb the remainder of the template.

The resulting file is valid Dart: it compiles, and dart analyze reports
"No issues found." The injected code executes whenever the corresponding
localization getter is called (e.g. AppLocalizations.of(context).greeting(...)).

The tool applies the exact identifier check it needs to the resource name
but not to the sibling type field that ends up in the same generated source.

Code sample

app_en.arb:

{
  "@@locale": "en",
  "greeting": "Hello {user}",
  "@greeting": {
    "placeholders": {
      "user": {
        "type": "Object user) { print('>>> ARBITRARY DART EXECUTED FROM A TRANSLATION FILE <<<'); return 'pwned'; } String injectedByTranslation(Object"
      }
    }
  }
}

Generated app_localizations_en.dart after flutter gen-l10n:

class AppLocalizationsEn extends AppLocalizations {
  AppLocalizationsEn([String locale = 'en']) : super(locale);

  @override
  String greeting(Object user) {
    print('>>> ARBITRARY DART EXECUTED FROM A TRANSLATION FILE <<<'); // injected
    return 'pwned';
  }

  String injectedByTranslation(Object user) { // injected member
    return 'Hello $user';
  }
}

dart analyze on the generated file returns "No issues found!".

Screenshots or Video

Image

Logs

No response

Flutter Doctor output

N/A

Activity

  1. Badranh commented on Sep 1, 2026

    @Badranh
    Author

    app.zip

    App sample

  2. suryaKommana2662 commented on Sep 2, 2026

    @suryaKommana2662
    Contributor

    @Badranh Thanks for the report. I was able to reproduce the reported issue using the provided sample.

    flutter gen-l10n successfully processed the crafted .arb file and generated Dart source containing the injected code. dart analyze did not report any errors related to the injected code and I also ran the application with flutter run -d chrome and confirmed that the injected localization output is used at runtime. The application displayed:

    PWNED by a translation file (original was: Hello {user})

    Routing to the team-tool for further investigation

  3. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    team-toolOwned by Flutter Tool team
    a: internationalizationSupporting other languages or locales. (aka i18n)
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Sep 2, 2026
  4. added
    P2Important issues not at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Sep 8, 2026
  5. github-actions commented on Sep 24, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Sep 24, 2026
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

    P2Important issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions