question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] - Errors ignored during multiple security checking

See original GitHub issue

This lines bellow are invalid : packages/cli/src/routeGeneration/templates/express.hbs#L128 packages/cli/src/routeGeneration/templates/express.hbs#L136 packages/cli/src/routeGeneration/templates/hapi.hbs#L109 packages/cli/src/routeGeneration/templates/koa.hbs#L97

Sorting

  • I’m submitting a …

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn’t already been submit

Steps to Reproduce

  @Security('publicAccess')
  @Security('accessToken') // This one should be invalid and throw an error but nothing happened
  @Get('verifyToken')
  public async verifyToken(): Promise<void> {
    // ...
  }

Detailed Description

Because currently in my code I’m using multi @Security and the thing is if one of those failed, only the last one will be reported ! Plus, expressAuthentication(request, name, secMethod[name]) is executed before to be pushed on the promise stack. It mean in the case of expressAuthentication failed in synchro way then the app will literally crash.

Expected Behavior

[info] GET /api/v1/verifyToken?accessToken=&publicToken=test 400 // ERROR INVALID ACCESS TOKEN

Current Behavior

[info] GET /api/v1/verifyToken?accessToken=&publicToken=test  200

Possible Solution

To replace in /packages/cli/src/routeGeneration/templates/express.hbs#128 file

  function authenticateMiddleware(security: TsoaRoute.Security[] = []) {
    return (request: any, _response: any, next: any) =>
      new Promise((resolve, reject) => {
        const promises: Promise<any>[] = [];
        for (const secMethod of security) {
          for (const name in secMethod) {
            promises.push(expressAuthentication(request, name, secMethod[name]));
          }
        }
        Promise.all(promises)
          .then(resolve)
          .catch(reject);
      }).then((results: any) => {
        request['user'] = results.shift();
        next();
      }).catch((error) => {
        error.status = error.status || 401;
        next(error)
      });
  };

More

I saw on tests that the logic is :

  • if security one is not ok then we choose security two
  • or if security two is not ok then we choose security one

But I think we should choose this kind of logic :

  • Ok I set a security on my route then it must be verify
  • EXCEPT is the second parameter is OPTIONAL Ex:
@Security('publicAccess') // SHOULD BE VERIFY EVEN IF BELLOW THERE ANOTHER SECURITY
@Security('accessToken', ['optional']) // THIS ONE IS OPTIONAL SO IF THE VERIFICATION FAILED THAT IS NOT A PROBLEM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
michalzaq12commented, Jan 6, 2021

@dobobaie try to use @Security({'publicAccess': [], 'accessToken': []})

0reactions
github-actions[bot]commented, Feb 15, 2021

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore issues - Snyk User Docs
Scanning from the CLI or CI/CD, ignoring in the Web UI​​ Ignores between a CLI (or CI/CD run) and the Snyk UI are...
Read more >
How to Fix NET::ERR_CERT_REVOKED Error in Chrome, IE ...
A brief guide to fix ERR Cert revoked Error in Chrome, IE, Mac and ... Since it is an SSL error, it may...
Read more >
Ignore an Issue in SCA - Veracode Docs
If you ignore an issue, the issue remains ignored in future scans of the project, even if the issue severity changes or a...
Read more >
Ignoring Checks - tfsec - Aqua Security
Ignoring checks can be scoped to a workspace level. If you add the ws: declaration to your ignore it will only be honoured...
Read more >
How to get the number of inserts/error/ignored of - ServiceNow
Hello All, Please help me understand how can we get the number of errors or insert on import_status page from script as shown...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found