Skip to content
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

Change audit.ignore behavior before 2.6.0 #11605

Merged
merged 7 commits into from Sep 1, 2023
Merged

Conversation

mxr576
Copy link
Contributor

@mxr576 mxr576 commented Aug 30, 2023

Closes #11604

res/composer-schema.json Outdated Show resolved Hide resolved
@mxr576 mxr576 force-pushed the audit-pass branch 2 times, most recently from a8b998b to c66fd04 Compare August 30, 2023 15:01
@Seldaek Seldaek added this to the 2.6 milestone Aug 30, 2023
$pkgPlurality = $ignoredAffectedPackagesCount === 1 ? '' : 's';
$punctuation = $format === 'summary' ? '.' : ':';
$io->writeError("<info>$ignoredTotalAdvisoryCount ignored security vulnerability advisor{$plurality} affecting $ignoredAffectedPackagesCount package{$pkgPlurality}{$punctuation}</info>");
$this->outputAdvisories($io, $ignoredAdvisories, $format);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we may have the reason for ignoring a given security advisory, I'd consider adding that to the output (also to the JSON above). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yes makes sense to me. It probably needs to be highlighted like <warning>Ignored: $reason</>

And for the table output add an Ignore column with Yes/empty and no reason to keep it small perhaps, because otherwise the table width will blow up

Copy link
Contributor Author

@mxr576 mxr576 Aug 31, 2023

Choose a reason for hiding this comment

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

Yes makes sense to me. It probably needs to be highlighted like Ignored: $reason</>

Just to be clear, do you mean display all ignore reasons as console message unless the output format is JSON?

Speaking of JSON, partially because the JSON output leverages that advisories are JSON serializable, should I just introduce a new class IgnoredSecurityAdvisory extends SecurityAdvisory{} that can also hold the reason?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was also wondering how to best achieve this. For sure for JSON it would be easier with a subclass..

For the plain text output I meant it probably should go here https://github.com/composer/composer/blob/main/src/Composer/Advisory/Auditor.php#L207 as a new line with a so it is highlighted as being ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to me that wrapping text in tables works OOTB, so is there any need for workarounds like...?

                $ignoreReason = '';
                if ($advisory instanceof IgnoredSecurityAdvisory && $advisory->ignoreReason !== NULL) {
                    if (strlen($advisory->ignoreReason) > 80) {
                        $ignoreReason = substr($advisory->ignoreReason, 0, 77) . '...';
                    }
                    else {
                        $ignoreReason = $advisory->ignoreReason;
                    }
                }

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A better example

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mxr576 mxr576 force-pushed the audit-pass branch 2 times, most recently from f8e5182 to b0a7d05 Compare August 31, 2023 10:51
@mxr576 mxr576 requested a review from Seldaek August 31, 2023 10:51
@mxr576 mxr576 changed the title Replace audit.ignore with audit.pass Change audit.ignore behavior before 2.6.0 Aug 31, 2023
@mxr576 mxr576 force-pushed the audit-pass branch 2 times, most recently from e570c5a to 708db5e Compare August 31, 2023 13:57
src/Composer/Advisory/Auditor.php Outdated Show resolved Hide resolved
}
else {
if ($advisory instanceof SecurityAdvisory) {
$advisory = new IgnoredSecurityAdvisory(
Copy link
Contributor

Choose a reason for hiding this comment

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

should we create an object that extends SecurityAdvisory in which you copy all the metadata or should we rather have a IgnoredSecurityAdvisory that would take a SecurityAdvisory|PartialSecurityAdvisory as argument and implements its jsonSerialize method by adding an ignore_reason key in the array returned by the delegated call ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were the options that I also considered, the solution in the PR just felt better, even if it is "ugly" a bit.

Copy link
Contributor

@fredden fredden Aug 31, 2023

Choose a reason for hiding this comment

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

Perhaps IgnoredSecurityAdvisory could be a proxy class or have a factory method which takes in a SecurityAdvisory object. That'd make the code here much cleaner.

$advisory = IgnoredSecurityAdvisory::create($advisory, $ignoreReason); or $advisory = new IgnoredSecurityAdvisory($advisory, $ignoreReason);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IgnoredSecurityAdvisory::createFromSecurityAdvisory($advisory I would have gone with this approach by default, but since everything in public on these objects (as public properties) this approach just moves copying object data to somewhere else. Would that have a real added value? In this case, should I make the constructor of IgnoredSecurityAdvisory private so it could be only constructed from a SecurityAdvisory from now?

}
else {
if ($advisory instanceof SecurityAdvisory) {
$advisory = new IgnoredSecurityAdvisory(
Copy link
Contributor

@fredden fredden Aug 31, 2023

Choose a reason for hiding this comment

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

Perhaps IgnoredSecurityAdvisory could be a proxy class or have a factory method which takes in a SecurityAdvisory object. That'd make the code here much cleaner.

$advisory = IgnoredSecurityAdvisory::create($advisory, $ignoreReason); or $advisory = new IgnoredSecurityAdvisory($advisory, $ignoreReason);

$advisory->cve,
$advisory->link
);
if ($ignoreReason !== NULL) {
Copy link
Contributor

@fredden fredden Aug 31, 2023

Choose a reason for hiding this comment

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

I thought that the reason was a required field.

Edit: I've now seen that there are two accepted values and only one has the 'reason' field. I'd vote that a reason should always be provided/required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doc/06-config.md Outdated Show resolved Hide resolved
res/composer-schema.json Outdated Show resolved Hide resolved
res/composer-schema.json Outdated Show resolved Hide resolved
@Seldaek
Copy link
Member

Seldaek commented Aug 31, 2023

@mxr576 please don't change anything anymore, I'm editing a couple things here and then merging :) thanks a lot for the quick work here!

@Seldaek
Copy link
Member

Seldaek commented Aug 31, 2023

I think it looks good now but I perhaps broke some tests.. anyway bedtime, will wrap up tomorrow.

@mxr576
Copy link
Contributor Author

mxr576 commented Aug 31, 2023

@mxr576 please don't change anything anymore, I'm editing a couple things here and then merging :) thanks a lot for the quick work here!

Roger! 🙂 Time well spent! 🍻

@Seldaek Seldaek merged commit 0ab4dfb into composer:main Sep 1, 2023
20 checks passed
@Seldaek
Copy link
Member

Seldaek commented Sep 1, 2023

Ok looking good, thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants