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

fix: validate RepositoryVulnerabilityAlert to getVulnerability #13788

Merged
merged 6 commits into from Jan 25, 2022

Conversation

sugarshin
Copy link
Contributor

@sugarshin sugarshin commented Jan 25, 2022

Hi, there. This pull-request is related to #11911 and solves it.

Now, I facing this problem too. The problem of #11911 is caused by the Renovate does not null-check for it. As GitHub documentation, securityVulnerability is nullable. but, I think fixing it to be greatly affected, such as proper TypeScript type definitions.

And, I think this line of logging with error and exiting with non-zero status code related to the above problem is not appropriate because the try-catch here is a process to parse the vulnerability alerts for just logging. It means not affected to getVulnerabilityAlerts() return values. And is not related to the original execution behavior of the Renovate.

So I think logger.warn is better.

Changes:

Validate for securityVulnerability to skip processing parse RepositoryVulnerabilityAlert entity for logger.

Context:

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@CLAassistant
Copy link

CLAassistant commented Jan 25, 2022

CLA assistant check
All committers have signed the CLA.

@JamieMagee
Copy link
Contributor

Can you open an issue to discuss this issue? Using logger.error doesn't make Renovate exit with a non-zero exit code. You can argue that it should be warning because it's a recoverable error, but I don't think that this change alone will solve the issue you're seeing.

@sugarshin
Copy link
Contributor Author

sugarshin commented Jan 25, 2022

@JamieMagee Thank you for your reply.

logger.error doesn't make Renovate exit with a non-zero exit code

No, logger.error does make Renovate exit with a non-zero status code. Could you check following?

  • const loggerErrors = getProblems().filter((p) => p.level >= ERROR);
    if (loggerErrors.length) {
    logger.info(
    { loggerErrors },
    'Renovate is exiting with a non-zero code due to the following logged errors'
    );
    return 1;
    }
  • process.exitCode = await globalWorker.start();

@JamieMagee
Copy link
Contributor

My mistake! Okay, then this may well be the fix. Can you still give me a bit more information about your setup? The original issue you linked was running on GHES and for the npm package hoek. What sort of setup is causing this error for you?

@sugarshin
Copy link
Contributor Author

sugarshin commented Jan 25, 2022

@JamieMagee Thank you! I'm using Renovate bot with self-hosting.

The global config is the following:

module.exports = {
  endpoint: 'https://<my-company-ghe-domain>/api/v3/',
  token: process.env.GHE_TOKEN,
  platform: 'github',
  logLevel: 'debug',
  onboardingConfig: {
    extends: ['config:base'],
  },
  cacheDir: __dirname + '/.renovate_cache',
  dryRun: !!process.env.RENOVATE_DRYRUN,
  autodiscover: false,
  packageRules: [
    {
      matchDatasources: ['docker'],
      registryUrls: ['<masked>']
    }
  ],
  repositories: [
    // repositories
  ],
};

The config of the repository where this problem occurs is the following:

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "config:base"
  ],
  "ignorePaths": [
    "**/node_modules/**"
  ],
  "packageRules": [
    {
      "matchDepTypes": ["major"],
      "enabled": false
    },
    {
      "matchDepTypes": ["devDependencies"],
      "addLabels": ["devDependencies"]
    }
  ],
  "labels": ["renovate"]
}

The screenshot of error log:

ss

@sugarshin
Copy link
Contributor Author

sugarshin commented Jan 25, 2022

And, I executed with LOG_LEVEL=trace to test. The log content of the following line:

{
    "name": "renovate",
    "hostname": "<masked>",
    "pid": 709,
    "level": 10,
    "logContext": "MjvOWnPA6xLTJre-KECJU",
    "repository": "<masked>",
    "alerts": [
        {
            "dismissReason": null,
            "vulnerableManifestFilename": "package-lock.json",
            "vulnerableManifestPath": "package-lock.json",
            "vulnerableRequirements": "= 2.2.1",
            "securityAdvisory": null,
            "securityVulnerability": null
        },
        ...
    ],
    "msg": "GitHub vulnerability details",
    "time": "2022-01-24T08:10:32.377Z",
    "v": 0
}

As you can see, the "alerts" includes items that "securityVulnerability" is null.

@rarkins
Copy link
Collaborator

rarkins commented Jan 25, 2022

Seems like a faulty alert?

I'd prefer to fix the validation (eg so that we can still process the non faulty ones) than simply lower the log severity

@sugarshin
Copy link
Contributor Author

@rarkins Thank you for your comment.

I'd prefer to fix the validation (eg so that we can still process the non faulty ones)

Ok, I agree with you. I will fix it later.

@JamieMagee
Copy link
Contributor

@sugarshin Can you give me the package name for the malformed vulnerability alert? Maybe I can follow-up internally about it.

@sugarshin
Copy link
Contributor Author

sugarshin commented Jan 25, 2022

@JamieMagee Thank you. I couldn't determine which package, but I have several candidates:

app-root-path@2.2.1
ansi-styles@2.2.1
cli-width@2.2.1
readdirp@2.2.1
md5@2.2.1
underscore.string@2.2.1
tapable@2.2.1

Could you check it?

@sugarshin
Copy link
Contributor Author

@rarkins I fixed it, so could you check it?

@sugarshin sugarshin changed the title chore: logging without error to getVulnerability chore: validate RepositoryVulnerabilityAlert to getVulnerability Jan 25, 2022
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

lib/platform/github/index.ts Outdated Show resolved Hide resolved
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
@viceice viceice changed the title chore: validate RepositoryVulnerabilityAlert to getVulnerability fix: validate RepositoryVulnerabilityAlert to getVulnerability Jan 25, 2022
@viceice
Copy link
Member

viceice commented Jan 25, 2022

I think this will also fix #13796

@rarkins rarkins merged commit 5df664c into renovatebot:main Jan 25, 2022
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 31.53.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants