Skip to content

QuestionHelper input truncated at 4095 byte #47586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pbek opened this issue Sep 15, 2022 · 5 comments · Fixed by #47588
Closed

QuestionHelper input truncated at 4095 byte #47586

pbek opened this issue Sep 15, 2022 · 5 comments · Fixed by #47588

Comments

@pbek
Copy link
Contributor

pbek commented Sep 15, 2022

Symfony version(s) affected

6.2

Description

When you ask for input with QuestionHelper the input is truncated at 4096 byte.
The maximum line length in unix terminals is 4096. QuestionHelper additionally only reads the first 4096 byte of the input in:

$value = fgets($inputStream, 4096);

How to reproduce

# Enter a very long string here
php bin/console secrets:set CERT_P12
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
        $io = new SymfonyStyle($input, $errOutput);

        $value = $io->askHidden('Please type the secret value');
    }

See:

$value = $io->askHidden('Please type the secret value');

The content of $value is truncated to 4095 byte when you enter a text longer than that.

Possible Solution

Maybe a warning should be printed when an input has exactly 4095 characters to alert the user that there is the possibility that something was truncated.

Additional Context

Use case:
We use the Symfony CLI to set secrets (SecretsSetCommand, secret:set). We have very long strings, like base64 encoded certificates in our secrets.

@pbek pbek added the Bug label Sep 15, 2022
@xabbuh xabbuh added the Console label Sep 15, 2022
@pbek pbek changed the title QuestionHelper input truncated at 4096 byte QuestionHelper input truncated at 4095 byte Sep 15, 2022
pbek added a commit to pbek/symfony that referenced this issue Sep 15, 2022
@pbek
Copy link
Contributor Author

pbek commented Sep 15, 2022

#47587 would add a warning in SecretsSetCommand.

@pbek
Copy link
Contributor Author

pbek commented Sep 15, 2022

#47588 would add a warning in QuestionHelper.

pbek added a commit to pbek/symfony that referenced this issue Sep 21, 2022
Co-authored-by: Fabien Potencier <fabien@potencier.org>
pbek added a commit to pbek/symfony that referenced this issue Sep 21, 2022
Co-authored-by: Fabien Potencier <fabien@potencier.org>
@pbek
Copy link
Contributor Author

pbek commented Sep 21, 2022

Just a note: If #47588 would get accepted, #47587 is redundant and can be ignored.

@fabpot
Copy link
Member

fabpot commented Sep 21, 2022

@pbek Can you do everything in the same PR? That would help with the reviews and ensure that it's all consistent. Thank you.

@pbek
Copy link
Contributor Author

pbek commented Sep 21, 2022

@fabpot, #47588 is the one PR that would solve the matter at the source of the problem. If it's ok to solve the matter at the source and not only in SecretsSetCommand, I'd close #47587.

@fabpot fabpot closed this as completed Sep 23, 2022
fabpot added a commit that referenced this issue Sep 23, 2022
…elper (#47586) (pbek)

This PR was squashed before being merged into the 6.2 branch.

Discussion
----------

Add warning for possibly truncated inputs in QuestionHelper (#47586)

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| Tickets       | Fix #47586
| License       | MIT

Adds a warning for possibly truncated inputs in `QuestionHelper`.

Commits
-------

806aa1b Add warning for possibly truncated inputs in QuestionHelper (#47586)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants