romainbessugesmeusy / netlify-plugin-auth0-patch-urls

A Netlify Build plugin that makes Auth0 works with deploy previews
MIT License
7 stars 3 forks source link

Remove confidential properties from thrown errors #16

Open ehmicky opened 4 years ago

ehmicky commented 4 years ago

When the main HTTP request fails, the thrown error has some static properties which are confidential. Some get sanitized (see [SANITIZED] below), but others remain (see [NOT SANITIZED] below).

5:51:11 PM: ┌─────────────────────────────────────────────────────────┐
5:51:11 PM: │ Plugin "netlify-plugin-auth0-patch-urls" internal error │
5:51:11 PM: └─────────────────────────────────────────────────────────┘
5:51:11 PM: ​
5:51:11 PM:   Error message
5:51:11 PM:   UnhandledRejection: {"error":"access_denied","error_description":"Unauthorized"}
5:51:11 PM: ​
5:51:11 PM:   Plugin details
5:51:11 PM:   Package:        netlify-plugin-auth0-patch-urls
5:51:11 PM:   Version:        1.2.2
5:51:11 PM:   Repository:     git+https://github.com/romainbessugesmeusy/netlify-plugin-auth0-patch-urls.git
5:51:11 PM:   npm link:       https://www.npmjs.com/package/netlify-plugin-auth0-patch-urls
5:51:11 PM:   Report issues:  https://github.com/romainbessugesmeusy/netlify-plugin-auth0-patch-urls/issues
5:51:11 PM: ​
5:51:11 PM:   Error location
5:51:11 PM:   In "onPreBuild" event in "netlify-plugin-auth0-patch-urls" from netlify.toml and package.json
5:51:11 PM:       at /opt/build/repo/node_modules/rest-facade/src/Client.js:387:27
5:51:11 PM:       at Request.callback (/opt/build/repo/node_modules/superagent/lib/node/index.js:728:3)
5:51:11 PM:       at parser (/opt/build/repo/node_modules/superagent/lib/node/index.js:916:18)
5:51:11 PM:       at IncomingMessage.res.on (/opt/build/repo/node_modules/superagent/lib/node/parsers/json.js:19:7)
5:51:11 PM:       at IncomingMessage.emit (events.js:203:15)
5:51:11 PM:       at endReadableNT (_stream_readable.js:1129:12)
5:51:11 PM:       at process._tickCallback (internal/process/next_tick.js:63:19)
5:51:11 PM: ​
5:51:11 PM:   Error properties
5:51:11 PM:   {
5:51:11 PM:     statusCode: 401,
5:51:11 PM:     requestInfo: {
5:51:11 PM:       method: 'post',
5:51:11 PM:       url: 'https://syllabird-test.auth0.com/oauth/token'
5:51:11 PM:     },
5:51:11 PM:     originalError: {
5:51:11 PM:       status: 401,
5:51:11 PM:       response: {
5:51:11 PM:         req: {
5:51:11 PM:           method: 'POST',
5:51:11 PM:           url: 'https://syllabird-test.auth0.com/oauth/token',
5:51:11 PM:           data: {
5:51:11 PM:             grant_type: 'client_credentials',
5:51:11 PM:             client_id: '[NOT SANITIZED]',
5:51:11 PM:             client_secret: '[SANITIZED]',
5:51:11 PM:             scope: 'read:clients update:clients',
5:51:11 PM:             audience: 'https://syllabird-test.auth0.com/api/v2/'
5:51:11 PM:           },
5:51:11 PM:           headers: {
5:51:11 PM:             'user-agent': 'node.js/10.16.0',
5:51:11 PM:             'content-type': 'application/json',
5:51:11 PM:             'auth0-client': '[NOT SANITIZED]',
5:51:11 PM:             accept: 'application/json'
5:51:11 PM:           }
5:51:11 PM:         },
5:51:11 PM:         header: {
5:51:11 PM:           date: 'Tue, 09 Jun 2020 15:51:11 GMT',
5:51:11 PM:           'content-type': 'application/json',
5:51:11 PM:           'content-length': '60',
5:51:11 PM:           connection: 'close',
5:51:11 PM:           server: 'nginx',
5:51:11 PM:           'ot-tracer-spanid': '[NOT SANITIZED]',
5:51:11 PM:           'ot-tracer-traceid': '[NOT SANITIZED]',
5:51:11 PM:           'ot-tracer-sampled': 'true',
5:51:11 PM:           'ot-baggage-auth0-request-id': '[NOT SANITIZED]',
5:51:11 PM:           'x-auth0-requestid': '[NOT SANITIZED]',
5:51:11 PM:           'set-cookie': [
5:51:11 PM:             '[NOT SANITIZED]; Max-Age=31557600; Path=/; Expires=Wed, 09 Jun 2021 21:51:11 GMT; HttpOnly; Secure; SameSite=None',
5:51:11 PM:             '[NOT SANITIZED]; Max-Age=31557600; Path=/; Expires=Wed, 09 Jun 2021 21:51:11 GMT; HttpOnly; Secure'
5:51:11 PM:           ],
5:51:11 PM:           'x-ratelimit-limit': '30',
5:51:11 PM:           'x-ratelimit-remaining': '29',
5:51:11 PM:           'x-ratelimit-reset': '1591717872',
5:51:11 PM:           'cache-control': 'private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform'
5:51:11 PM:         },
5:51:11 PM:         status: 401,
5:51:11 PM:         text: '{"error":"access_denied","error_description":"Unauthorized"}'
5:51:11 PM:       }
5:51:11 PM:     }
5:51:11 PM:   }

Since error static properties get printed in build logs, and build logs might be public, the error should be handled and those properties should be sanitized or removed.