Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] Fix security issue on CsvEncoder about CSV injection#24508

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@welcoMattic
Copy link
Member

@welcoMatticwelcoMattic commentedOct 10, 2017
edited
Loading

QA
Branch?master (4.1)
Bug fix?no
New feature?yes
BC breaks?yes
Deprecations?no
Tests pass?yes
LicenseMIT

I readthis article about CSV injection and I thought it best to update theCsvEncoder so that it does not generate potentially malicious CSV files by default.

sstok, theofidry, and mjanser reacted with thumbs up emojiostrolucky reacted with thumbs down emoji
@sroze
Copy link
Contributor

Great initiative 👍 I'd target 3.4.

Copy link
Member

@javiereguiluzjaviereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In addition to prefixing a\t to problematic values, another solution proposed in the comments of the article is to prefix a= before the"..." because that forces Excel to interpret the value as text. Not sure if it's really better.

@welcoMatticwelcoMatticforce-pushed thefix/csv-encoder-formulas-char-escaping branch from6d7dc03 toe254fcbCompareOctober 10, 2017 13:34
@xabbuhxabbuh added this to the4.1 milestoneOct 11, 2017
@welcoMattic
Copy link
MemberAuthor

Thanks@chalasr@kaznovac@xabbuh for your comments and review.
I just push fixes. I'm agree to set$escapeFormulas atfalse by default, after all negative numbers doesn't have to be escaped. And it will avoid BC Break.

Should I replace allassertEquals byassertSame inCsvEncoderTest class?

@welcoMatticwelcoMatticforce-pushed thefix/csv-encoder-formulas-char-escaping branch from527dc6a tofc743a1CompareOctober 11, 2017 08:38
@chalasr
Copy link
Member

@welcoMattic Nope, that would create merge conflicts when merging lower branches up to master. Thanks.

@xabbuh
Copy link
Member

Should we also allow to pass this option through the context so that you do not necessary have to configure this option globally?

@welcoMattic
Copy link
MemberAuthor

@xabbuh why not. We should also make the context$escapeFormulas value overrides the global$escapeFormulas value. It could be set totrue globally, but for one particular encoding it could be set tofalse.

@chalasr
Copy link
Member

👍 to allow overriding this option in the context.

@welcoMatticwelcoMatticforce-pushed thefix/csv-encoder-formulas-char-escaping branch 2 times, most recently from09a5ed5 to9c0733dCompareOctober 11, 2017 13:48
@welcoMattic
Copy link
MemberAuthor

@chalasr@xabbuh Overriding is now possible

@dunglas
Copy link
Member

Great!

But as stated in the article, it's definitely not a security issue on our side. The current implementation respects the RFC (Excel and Google Sheets don't), and most software consuming CSV expect the current behavior.
It should made be clear in the docs PR that this option should only be used when the generated CSV will be imported in spreadsheets or it can cause interoperability issues.

jvasseur and ostrolucky reacted with thumbs up emoji

@welcoMattic
Copy link
MemberAuthor

Thanks@dunglas!

For documentation, should I create a new page underSerializer section? Named CsvEncoder, and where I explain why this options exists?

@ostrolucky
Copy link
Contributor

ostrolucky commentedOct 16, 2017
edited
Loading

Alternative approach might be to just add a normalizer. That would help with deserialization of such sanitized csvs too and doesn't pollute __construct arguments.

I don't like having this in core anyway though, as it's security issue in Excel and Google sheets only and this is destructive kind of escaping

@fabpot
Copy link
Member

Not sure if we need to support that in core. /cc @symfony/mergers

@Tobion
Copy link
Contributor

👍 to include that as it's security feature that people should be aware about.

Copy link
Contributor

@dbudbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i think in 95% of the use cases, the serializer will be used to export data, which might include user provided input.

there is only a problem if this component is used to generate sheets with formula. i would add an explaination in the phpdoc to explain what this flag is about and say to set it to true when you don't intend to have formula in the csv you generate.

i am no merger, but +1 on this. it is a relevant security topic and obviously excel/libreoffice/google and whoever else is affected decided they rather not properly fix it, so its up to generators of csv files to ensure security.

i think this should be against 3.3 as that is the branch for security fixes.

@dunglas
Copy link
Member

👍 to support this feature too. But as it's definitely not a security fix (on our side), it's a new feature that should be merged in 4.1.

there is only a problem if this component is used to generate sheets with formula.

There is also a problem when the value start with'=', '-', '+', '@' and the parser supports correctly the RFC: a\t will be added, but it should not (actually, when using this flag, it's not really a true CSV file anymore).

welcoMattic reacted with thumbs up emoji

@welcoMattic
Copy link
MemberAuthor

Thanks@dbu@dunglas for your comments. I think that we can support this "fix" and explain it explicitly in PHPDoc.

Should I update the PR now, or we need to wait other opinions?

@dbu
Copy link
Contributor

dbu commentedDec 20, 2017
edited
Loading

i'd update the changelog and phpdoc as that will be relevant either way. i hope one of the maintainers can decide which version this should go. i can see the point of kevin, and its a good reason why its not on by default. but i feel it still is security relevant, even if its not a bug of symfony, but symfony helping around lax security of other tools - and as such should go into 3.3 or 3.4.

@dunglas
Copy link
Member

I think that you can update and rebase the PR@welcoMattic

@welcoMattic
Copy link
MemberAuthor

@nicolas-grekas Done, I also fix@ostrolucky's comment.

@nicolas-grekas
Copy link
Member

@welcoMattic thanks. Can you rebase to get rid of the merge commit? I invite you to squash while doing so.

@welcoMatticwelcoMatticforce-pushed thefix/csv-encoder-formulas-char-escaping branch 2 times, most recently fromb98b9ab to414a61dCompareFebruary 4, 2018 18:30
private$formulasStartCharacters =array('=','-','+','@');

publicfunction__construct(string$delimiter =',',string$enclosure ='"',string$escapeChar ='\\',string$keySeparator ='.')
publicfunction__construct(string$delimiter =',',string$enclosure ='"',string$escapeChar ='\\',string$keySeparator ='.',$escapeFormulas =false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

missing bool type declaration for the new argument

@welcoMatticwelcoMatticforce-pushed thefix/csv-encoder-formulas-char-escaping branch from414a61d toa1b0bdbCompareFebruary 6, 2018 10:21
@welcoMattic
Copy link
MemberAuthor

Thanks for review@Tobion 👍

@fabpot
Copy link
Member

Thank you@welcoMattic.

welcoMattic reacted with thumbs up emoji

@fabpotfabpot merged commita1b0bdb intosymfony:masterFeb 7, 2018
fabpot added a commit that referenced this pull requestFeb 7, 2018
…V injection (welcoMattic)This PR was merged into the 4.1-dev branch.Discussion----------[Serializer] Fix security issue on CsvEncoder about CSV injection| Q             | A| ------------- | ---| Branch?       | master (4.1)| Bug fix?      | no| New feature?  | yes| BC breaks?    | yes| Deprecations? | no| Tests pass?   | yes| License       | MITI read [this article](http://georgemauer.net/2017/10/07/csv-injection.html) about CSV injection and I thought it best to update the `CsvEncoder` so that it does not generate potentially malicious CSV files by default.Commits-------a1b0bdb Fix security issue on CsvEncoder
@fabpotfabpot mentioned this pull requestMay 7, 2018
@welcoMatticwelcoMattic deleted the fix/csv-encoder-formulas-char-escaping branchFebruary 4, 2020 15:12
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@xabbuhxabbuhxabbuh left review comments

@chalasrchalasrchalasr left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas requested changes

@fabpotfabpotfabpot approved these changes

@dunglasdunglasdunglas approved these changes

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

+4 more reviewers

@kaznovackaznovackaznovac left review comments

@ostroluckyostroluckyostrolucky left review comments

@TobionTobionTobion left review comments

@dbudbudbu approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

13 participants

@welcoMattic@sroze@chalasr@xabbuh@dunglas@ostrolucky@fabpot@Tobion@dbu@nicolas-grekas@javiereguiluz@kaznovac@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp