Program: CWE-79
Project: CVE-2019-14667
Buggy source:
{% extends "./layout/default" %}

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, destinationType, journal) }}
{% endblock %}

{% block content %}
    <form method="POST" action="{{ route('transactions.convert.index.post', [destinationType.type|lower, journal.id]) }}" accept-charset="UTF-8"
          class="form-horizontal" id="store"
          enctype="multipart/form-data">
        <input name="_token" type="hidden" value="{{ csrf_token() }}">
        <div class="row">
            <div class="col-lg-10 col-md-12 col-sm-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ ('convert_options_'~sourceType.type~destinationType.type)|_ }}</h3>
                    </div>
                    <div class="box-body">
                        {{ ExpandedForm.staticText('type', sourceType.type|_) }}
                        {{ ExpandedForm.staticText('description', '<a href="'~route('transactions.show', journal.id)~'">'~journal.description~'</a>') }}
                        {{ ExpandedForm.staticText('date', journal.date.formatLocalized(monthAndDayFormat)) }}

                        {# in case of withdrawal #}
                        {% if sourceType.type == "Withdrawal" %}
                            {{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name|escape~'</a>') }}
                            {# if destination is cash, show (cash) #}
                            {% if destinationAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.staticText('destination_account_expense', '<span class="text-success">(cash)</a>') }}
                            {% else %}
                                {{ ExpandedForm.staticText('destination_account_expense', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
                            {% endif %}

                        {% endif %}

                        {# in case of deposit #}
                        {% if sourceType.type == "Deposit" %}
                            {# if source is cash, show (cash) #}
                            {% if sourceAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.staticText('source_account_revenue', '<span class="text-success">(cash)</a>') }}
                            {% else %}
                                {{ ExpandedForm.staticText('source_account_revenue', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name|escape~'</a>') }}
                            {% endif %}
                            {{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
                        {% endif %}

                        {# in case of transfer #}
                        {% if sourceType.type == "Transfer" %}
                            {{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name|escape~'</a>') }}
                            {{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
                        {% endif %}

                        {# ONE #}
                        {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Deposit' %}
                            <p><em>
                                    {{ trans('firefly.convert_explanation_withdrawal_deposit',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>
                            <p><em>
                                    {{ 'convert_please_set_revenue_source'|_ }}
                                </em>
                            </p>
                            {% if destinationAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.text('source_account_revenue', '') }}
                            {% else %}
                                {{ ExpandedForm.text('source_account_revenue', destinationAccount.name|escape) }}
                            {% endif %}
                        {% endif %}

                        {# TWO #}
                        {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Transfer' %}
                            <p><em>
                                    {{ trans('firefly.convert_explanation_withdrawal_transfer',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em></p>

                            <p>
                                <em>
                                    {{ 'convert_please_set_asset_destination'|_ }}

                                </em>
                            </p>
                            {{ ExpandedForm.activeLongAccountList('destination_account_asset', null) }}

                        {% endif %}

                        {# THREE #}
                        {% if sourceType.type == 'Deposit' and destinationType.type == 'Withdrawal' %}
                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_deposit_withdrawal',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>
                            <p>
                                <em>
                                    {{ 'convert_please_set_expense_destination'|_ }}

                                </em>
                            </p>
                            {% if sourceAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.text('destination_account_expense', '') }}
                            {% else %}
                                {{ ExpandedForm.text('destination_account_expense', destinationAccount.name|escape) }}
                            {% endif %}

                        {% endif %}

                        {# FOUR #}
                        {% if sourceType.type == 'Deposit' and destinationType.type == 'Transfer' %}

                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_deposit_transfer',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>
                            <p>
                                <em>
                                    {{ 'convert_please_set_asset_source'|_ }}

                                </em>
                            </p>
                            {{ ExpandedForm.activeLongAccountList('source_account_asset', null) }}
                        {% endif %}

                        {# FIVE #}
                        {% if sourceType.type == 'Transfer' and destinationType.type == 'Withdrawal' %}

                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_transfer_withdrawal',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>

                            <p>
                                <em>
                                    {{ 'convert_please_set_expense_destination'|_ }}
                                </em>
                            </p>

                            {{ ExpandedForm.text('destination_account_expense', destinationAccount.name|escape) }}

                        {% endif %}

                        {# SIX #}
                        {% if sourceType.type == 'Transfer' and destinationType.type == 'Deposit' %}


                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_transfer_deposit',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>

                            <p>
                                <em>
                                    {{ 'convert_please_set_revenue_source'|_ }}
                                </em>
                            </p>

                            {{ ExpandedForm.text('source_account_revenue', sourceAccount.name|escape) }}

                        {% endif %}

                    </div>
                    <div class="box-footer">
                        <a href="{{ route('transactions.show', journal.id) }}" class="btn btn-danger">{{ 'cancel'|_ }}</a>
                        <button type="submit" id="transaction-btn" class="btn btn-success pull-right">
                            {{ trans('form.convert_'~sourceType.type) }}
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>

{% endblock %}
{% block scripts %}
    <script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_VERSION }}"></script>
    <script type="text/javascript" src="v1/js/ff/common/autocomplete.js?v={{ FF_VERSION }}"></script>
    <script type="text/javascript" src="v1/js/ff/transactions/convert.js?v={{ FF_VERSION }}"></script>
{% endblock %}


Fixed version (ground truth):
{% extends "./layout/default" %}

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, destinationType, journal) }}
{% endblock %}

{% block content %}
    <form method="POST" action="{{ route('transactions.convert.index.post', [destinationType.type|lower, journal.id]) }}" accept-charset="UTF-8"
          class="form-horizontal" id="store"
          enctype="multipart/form-data">
        <input name="_token" type="hidden" value="{{ csrf_token() }}">
        <div class="row">
            <div class="col-lg-10 col-md-12 col-sm-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ ('convert_options_'~sourceType.type~destinationType.type)|_ }}</h3>
                    </div>
                    <div class="box-body">
                        {{ ExpandedForm.staticText('type', sourceType.type|_) }}
                        {{ ExpandedForm.staticText('description', '<a href="'~route('transactions.show', journal.id)~'">'~journal.description|escape~'</a>') }}
                        {{ ExpandedForm.staticText('date', journal.date.formatLocalized(monthAndDayFormat)) }}

                        {# in case of withdrawal #}
                        {% if sourceType.type == "Withdrawal" %}
                            {{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name|escape~'</a>') }}
                            {# if destination is cash, show (cash) #}
                            {% if destinationAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.staticText('destination_account_expense', '<span class="text-success">(cash)</a>') }}
                            {% else %}
                                {{ ExpandedForm.staticText('destination_account_expense', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
                            {% endif %}

                        {% endif %}

                        {# in case of deposit #}
                        {% if sourceType.type == "Deposit" %}
                            {# if source is cash, show (cash) #}
                            {% if sourceAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.staticText('source_account_revenue', '<span class="text-success">(cash)</a>') }}
                            {% else %}
                                {{ ExpandedForm.staticText('source_account_revenue', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name|escape~'</a>') }}
                            {% endif %}
                            {{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
                        {% endif %}

                        {# in case of transfer #}
                        {% if sourceType.type == "Transfer" %}
                            {{ ExpandedForm.staticText('source_account_asset', '<a href="'~route('accounts.show',[sourceAccount.id])~'">'~sourceAccount.name|escape~'</a>') }}
                            {{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
                        {% endif %}

                        {# ONE #}
                        {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Deposit' %}
                            <p><em>
                                    {{ trans('firefly.convert_explanation_withdrawal_deposit',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>
                            <p><em>
                                    {{ 'convert_please_set_revenue_source'|_ }}
                                </em>
                            </p>
                            {% if destinationAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.text('source_account_revenue', '') }}
                            {% else %}
                                {{ ExpandedForm.text('source_account_revenue', destinationAccount.name|escape) }}
                            {% endif %}
                        {% endif %}

                        {# TWO #}
                        {% if sourceType.type == 'Withdrawal' and destinationType.type == 'Transfer' %}
                            <p><em>
                                    {{ trans('firefly.convert_explanation_withdrawal_transfer',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em></p>

                            <p>
                                <em>
                                    {{ 'convert_please_set_asset_destination'|_ }}

                                </em>
                            </p>
                            {{ ExpandedForm.activeLongAccountList('destination_account_asset', null) }}

                        {% endif %}

                        {# THREE #}
                        {% if sourceType.type == 'Deposit' and destinationType.type == 'Withdrawal' %}
                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_deposit_withdrawal',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>
                            <p>
                                <em>
                                    {{ 'convert_please_set_expense_destination'|_ }}

                                </em>
                            </p>
                            {% if sourceAccount.accountType.type == "Cash account" %}
                                {{ ExpandedForm.text('destination_account_expense', '') }}
                            {% else %}
                                {{ ExpandedForm.text('destination_account_expense', destinationAccount.name|escape) }}
                            {% endif %}

                        {% endif %}

                        {# FOUR #}
                        {% if sourceType.type == 'Deposit' and destinationType.type == 'Transfer' %}

                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_deposit_transfer',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>
                            <p>
                                <em>
                                    {{ 'convert_please_set_asset_source'|_ }}

                                </em>
                            </p>
                            {{ ExpandedForm.activeLongAccountList('source_account_asset', null) }}
                        {% endif %}

                        {# FIVE #}
                        {% if sourceType.type == 'Transfer' and destinationType.type == 'Withdrawal' %}

                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_transfer_withdrawal',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>

                            <p>
                                <em>
                                    {{ 'convert_please_set_expense_destination'|_ }}
                                </em>
                            </p>

                            {{ ExpandedForm.text('destination_account_expense', destinationAccount.name|escape) }}

                        {% endif %}

                        {# SIX #}
                        {% if sourceType.type == 'Transfer' and destinationType.type == 'Deposit' %}


                            <p>
                                <em>
                                    {{ trans('firefly.convert_explanation_transfer_deposit',
                                        {
                                            amount: positiveAmount|formatAmount,
                                            sourceRoute: route('accounts.show', [sourceAccount.id]),
                                            sourceName: sourceAccount.name|escape,
                                            destinationRoute: route('accounts.show', [destinationAccount.id]),
                                            destinationName: destinationAccount.name|escape,
                                        })|raw }}
                                </em>
                            </p>

                            <p>
                                <em>
                                    {{ 'convert_please_set_revenue_source'|_ }}
                                </em>
                            </p>

                            {{ ExpandedForm.text('source_account_revenue', sourceAccount.name|escape) }}

                        {% endif %}

                    </div>
                    <div class="box-footer">
                        <a href="{{ route('transactions.show', journal.id) }}" class="btn btn-danger">{{ 'cancel'|_ }}</a>
                        <button type="submit" id="transaction-btn" class="btn btn-success pull-right">
                            {{ trans('form.convert_'~sourceType.type) }}
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>

{% endblock %}
{% block scripts %}
    <script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_VERSION }}"></script>
    <script type="text/javascript" src="v1/js/ff/common/autocomplete.js?v={{ FF_VERSION }}"></script>
    <script type="text/javascript" src="v1/js/ff/transactions/convert.js?v={{ FF_VERSION }}"></script>
{% endblock %}