aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

authenticated REST does not retry for clock skew - defaultRetryDecider using AWS.Response.code instead of AWS.Response.name #13192

Closed jbarnickol closed 5 months ago

jbarnickol commented 5 months ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

REST API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify CLI

Environment information

``` # Put output below this line System: OS: macOS 14.3.1 CPU: (8) arm64 Apple M1 Pro Memory: 1.09 GB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 21.6.2 - /opt/homebrew/bin/node npm: 10.2.4 - /opt/homebrew/bin/npm Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 123.0.6312.87 Safari: 17.3.1 npmPackages: @aws-sdk/client-cloudfront: ^3.423.0 => 3.484.0 @aws-sdk/lib-dynamodb: ^3.423.0 => 3.484.0 @aws-sdk/lib-storage: ^3.423.0 => 3.484.0 @babel/core: ^7.18.2 => 7.23.7 @babel/eslint-parser: ^7.18.2 => 7.23.3 @babel/preset-react: ^7.17.12 => 7.23.3 @creativebulma/bulma-tooltip: ^1.2.0 => 1.2.0 @egjs/grid: ^1.15.0 => 1.15.0 @emotion/react: ^11.10.0 => 11.11.3 @emotion/styled: ^11.10.0 => 11.11.0 @hello-pangea/color-picker: ^3.2.2 => 3.2.2 @hello-pangea/dnd: ^16.2.0 => 16.5.0 @mdi/js: ^7.2.96 => 7.4.47 @mdi/react: ^1.5.0 => 1.6.1 @monaco-editor/react: ^4.6.0 => 4.6.0 @mui/base: ^5.0.0-beta.23 => 5.0.0-beta.29 @mui/icons-material: ^5.8.4 => 5.15.2 @mui/lab: ^5.0.0-alpha.114 => 5.0.0-alpha.158 @mui/material: ^5.9.2 => 5.15.2 @mui/x-data-grid-pro: ^6.18.1 => 6.18.6 @mui/x-date-pickers-pro: ^6.14.0 => 6.18.6 @nivo/bar: ^0.84.0 => 0.84.0 @nivo/core: ^0.84.0 => 0.84.0 @nivo/line: ^0.84.0 => 0.84.0 @react-google-maps/api: ^2.19.3 => 2.19.3 @reactuses/core: ^5.0.6 => 5.0.6 @reduxjs/toolkit: ^2.0.1 => 2.0.1 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @reduxjs/toolkit-react: 1.0.0 @tanstack/query-codemods: 4.24.3 @tanstack/query-sync-storage-persister: ^5.14.2 => 5.15.4 @tanstack/react-query: ^5.14.2 => 5.15.4 @tanstack/react-query-devtools: ^5.14.5 => 5.15.4 @tanstack/react-query-persist-client: ^5.14.2 => 5.15.4 @types/autosuggest-highlight: ^3.2.3 => 3.2.3 @types/draft-js: ^0.11.12 => 0.11.16 @types/draftjs-to-html: ^0.8.4 => 0.8.4 @types/google.maps: ^3.54.10 => 3.55.2 @types/jsoneditor: ^9.9.5 => 9.9.5 @types/jsonpath: ^0.2.4 => 0.2.4 @types/lodash: ^4.14.191 => 4.14.202 @types/node: ^20.10.5 => 20.10.5 (16.9.1, 10.17.60) @types/object-hash: ^3.0.2 => 3.0.6 @types/psl: ^1.1.0 => 1.1.3 @types/react: ^18.2.45 => 18.2.46 @types/react-copy-to-clipboard: ^5.0.4 => 5.0.7 @types/react-dom: ^18.2.18 => 18.2.18 @types/react-draft-wysiwyg: ^1.13.8 => 1.13.8 @types/react-helmet: ^6.1.6 => 6.1.11 @types/react-infinite-scroller: ^1.2.5 => 1.2.5 @types/react-lazyload: ^3.2.3 => 3.2.3 @types/react-responsive: ^8.0.5 => 8.0.8 @types/react-signature-canvas: ^1.0.5 => 1.0.5 @types/react-slick: ^0.23.10 => 0.23.13 @types/react-table: ^7.7.15 => 7.7.18 @types/react-text-truncate: ^0.14.4 => 0.14.4 @types/react-timeago: ^4.1.3 => 4.1.7 @types/redux-logger: ^3.0.12 => 3.0.12 @types/sortablejs: ^1.15.0 => 1.15.7 @types/ua-parser-js: ^0.7.39 => 0.7.39 @types/uuid: ^9.0.1 => 9.0.7 @types/validator: ^13.7.14 => 13.11.7 @typescript-eslint/eslint-plugin: ^6.16.0 => 6.16.0 @typescript-eslint/parser: ^6.16.0 => 6.16.0 @vitejs/plugin-react-swc: ^3.5.0 => 3.5.0 @zootools/email-spell-checker: ^1.12.0 => 1.12.0 add-to-calendar-button-react: ^2.5.3 => 2.5.5 array-flat-polyfill: ^1.0.1 => 1.0.1 auto-fontsize: ^1.0.25 => 1.0.25 autosuggest-highlight: ^3.3.4 => 3.3.4 aws-amplify: ^6.0.18 => 6.0.18 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () aws-transcription-to-vtt: ^1.0.3 => 1.0.3 axios: ^1.6.3 => 1.6.3 btoa: ^1.2.1 => 1.2.1 bulma: ^0.9.3 => 0.9.4 caniuse-lite: ^1.0.30001439 => 1.0.30001572 crypto-secure-random-digit: ^1.0.10 => 1.0.10 css-loader: ^6.8.1 => 6.8.1 dayjs: ^1.10.7 => 1.11.10 deep-object-diff: ^1.1.3 => 1.1.9 draft-js: ^0.11.7 => 0.11.7 draftjs-to-html: ^0.9.1 => 0.9.1 eslint: ^8.56.0 => 8.56.0 eslint-config-standard: ^17.0.0 => 17.1.0 eslint-config-standard-react: ^13.0.0 => 13.0.0 eslint-plugin-import: ^2.26.0 => 2.29.1 eslint-plugin-n: ^16.5.0 => 16.6.0 eslint-plugin-node: ^11.1.0 => 11.1.0 eslint-plugin-promise: ^6.0.0 => 6.1.1 eslint-plugin-react: ^7.29.4 => 7.33.2 eslint-plugin-react-hooks: ^4.3.0 => 4.6.0 eslint-plugin-react-refresh: ^0.4.5 => 0.4.5 eslint-plugin-standard: ^5.0.0 => 5.0.0 exponential-backoff: ^3.1.0 => 3.1.1 fast-average-color: ^9.3.0 => 9.4.0 fast-deep-equal: ^3.1.3 => 3.1.3 fast-memoize: ^2.5.2 => 2.5.2 firebase: ^10.7.1 => 10.7.1 firebase/analytics: undefined () firebase/app: undefined () firebase/app-check: undefined () firebase/auth: undefined () firebase/auth/cordova: undefined () firebase/compat: undefined () firebase/compat/analytics: undefined () firebase/compat/app: undefined () firebase/compat/app-check: undefined () firebase/compat/auth: undefined () firebase/compat/database: undefined () firebase/compat/firestore: undefined () firebase/compat/functions: undefined () firebase/compat/installations: undefined () firebase/compat/messaging: undefined () firebase/compat/performance: undefined () firebase/compat/remote-config: undefined () firebase/compat/storage: undefined () firebase/database: undefined () firebase/firestore: undefined () firebase/firestore/lite: undefined () firebase/functions: undefined () firebase/installations: undefined () firebase/messaging: undefined () firebase/messaging/sw: undefined () firebase/performance: undefined () firebase/remote-config: undefined () firebase/storage: undefined () fsevents: ^2.3.3 => 2.3.3 fuse.js: ^7.0.0 => 7.0.0 graphql-tag: ^2.12.6 => 2.12.6 handlebars: ^4.7.7 => 4.7.8 html-react-parser: ^5.0.11 => 5.0.11 html-to-draftjs: ^1.5.0 => 1.5.0 html-to-image: ^1.11.11 => 1.11.11 immutability-helper: ^3.1.1 => 3.1.1 isbot: ^5.1.0 => 5.1.0 json-rules-engine: ^6.5.0 => 6.5.0 jsoneditor: ^10.0.0 => 10.0.0 jsoneditor-react: ^3.1.2 => 3.1.2 jsonpath: ^1.1.1 => 1.1.1 jszip: ^3.7.1 => 3.10.1 jszip-utils: ^0.1.0 => 0.1.0 linkify-html: ^4.1.3 => 4.1.3 linkify-react: ^4.1.3 => 4.1.3 linkifyjs: ^4.1.3 => 4.1.3 lint-staged: ^15.2.0 => 15.2.0 localforage: ^1.10.0 => 1.10.0 localforage-indexes: ^1.1.1 => 1.1.1 lodash: ^4.17.21 => 4.17.21 lottie-react: ^2.3.1 => 2.4.0 mui-one-time-password-input: ^2.0.1 => 2.0.1 mui-tel-input: ^5.0.0 => 5.0.0 nanoid: ^5.0.4 => 5.0.4 (3.3.7) notistack: ^3.0.1 => 3.0.1 object-hash: ^3.0.0 => 3.0.0 optionator: ^0.9.3 => 0.9.3 (0.8.3) pluralize: ^8.0.0 => 8.0.0 process: ^0.11.10 => 0.11.10 prop-types: ^15.8.1 => 15.8.1 psl: ^1.8.0 => 1.9.0 qrcode.react: ^3.1.0 => 3.1.0 react: ^18.2.0 => 18.2.0 react-autosuggest: ^10.1.0 => 10.1.0 react-bulma-components: ^4.0.7 => 4.1.0 react-c3js: ^0.1.20 => 0.1.20 react-calendly: ^4.2.0 => 4.3.0 react-circular-progressbar: ^2.0.4 => 2.1.0 react-color-extractor: ^1.1.2 => 1.1.2 react-contenteditable: ^3.3.6 => 3.3.7 react-copy-to-clipboard: ^5.0.4 => 5.1.0 react-data-table-component: ^7.5.2 => 7.5.4 react-device-detect: ^2.2.0 => 2.2.3 react-dom: ^18.2.0 => 18.2.0 react-draft-wysiwyg: ^1.14.5 => 1.15.0 react-draggable: ^4.4.5 => 4.4.6 react-dropzone: ^14.2.3 => 14.2.3 react-error-overlay: ^6.0.11 => 6.0.11 react-helmet: ^6.1.0 => 6.1.0 react-hide-on-mouse-stop: ^1.0.3 => 1.0.3 react-hook-form: ^7.43.5 => 7.49.2 react-image-crop: ^11.0.2 => 11.0.2 react-infinite-scroller: ^1.2.4 => 1.2.6 react-intersection-observer: ^9.5.2 => 9.5.3 react-lazyload: ^3.2.0 => 3.2.0 react-loading-skeleton: ^3.3.1 => 3.3.1 react-modal: ^3.14.4 => 3.16.1 react-multi-carousel: ^2.8.0 => 2.8.4 react-number-easing: ^1.0.2 => 1.0.2 react-number-easing-website: 1.0.0 react-pdf: ^7.1.2 => 7.6.0 react-player: ^2.9.0 => 2.14.1 react-player-controls: ^1.1.0 => 1.1.0 react-redux: ^9.0.4 => 9.0.4 (8.1.3) react-responsive: ^9.0.2 => 9.0.2 react-responsive-carousel: ^3.2.23 => 3.2.23 react-router-dom: ^6.2.1 => 6.21.1 react-scroll-horizontal: ^1.6.6 => 1.6.6 react-share: ^5.0.3 => 5.0.3 react-signature-canvas: ^1.0.6 => 1.0.6 react-slick: ^0.29.0 => 0.29.0 react-sortablejs: ^6.1.1 => 6.1.4 react-svg: ^16.1.33 => 16.1.33 react-table: ^7.7.0 => 7.8.0 react-text-truncate: ^0.19.0 => 0.19.0 react-textarea-autosize: ^8.3.2 => 8.5.3 react-timeago: ^7.2.0 => 7.2.0 react-tooltip: ^5.25.1 => 5.25.1 react-webcam: ^7.1.1 => 7.2.0 react_advanced_demo: 0.1.0 react_demo: 0.1.0 recharts: ^2.4.3 => 2.10.3 redux: ^5.0.1 => 5.0.1 (4.2.1) redux-logger: ^3.0.6 => 3.0.6 redux-persist: ^6.0.0 => 6.0.0 redux-persist/integration/react: undefined () redux-throttle: ^0.1.1 => 0.1.1 redux-thunk: ^3.1.0 => 3.1.0 reselect: ^5.0.1 => 5.0.1 (4.1.8) sass: ^1.49.0 => 1.69.6 sass-loader: ^13.3.3 => 13.3.3 screenfull: ^6.0.2 => 6.0.2 (5.2.0) slick-carousel: ^1.8.1 => 1.8.1 sortablejs: ^1.15.0 => 1.15.1 source-map-explorer: ^2.5.2 => 2.5.3 style-loader: ^3.3.3 => 3.3.3 ts-deepmerge: ^6.2.0 => 6.2.0 ts-loader: ^9.5.1 => 9.5.1 typescript: ^5.3.3 => 5.3.3 (4.9.5) ua-parser-js: ^1.0.37 => 1.0.37 (0.7.37) use-fit-text: ^2.4.0 => 2.4.0 use-fit-text-example: undefined () usehooks-ts: ^2.16.0 => 2.16.0 uuid: ^9.0.0 => 9.0.1 (8.3.2) validator: ^13.7.0 => 13.11.0 vite: ^5.0.10 => 5.0.10 vite-plugin-checker: ^0.6.2 => 0.6.2 vite-plugin-node-polyfills: ^0.19.0 => 0.19.0 vite-plugin-svgr: ^4.2.0 => 4.2.0 vite-tsconfig-paths: ^4.2.2 => 4.2.3 npmGlobalPackages: @aws-amplify/cli: 12.10.1 npm: 10.2.4 typescript: 5.3.3 ```

Describe the bug

I dug into this because our calls from browser to amplify API gateway are failing when clock is off by more than 5 minutes. It looks like an AWS sdk v2 => v3 breaking change was missed.

In the line of code core/src/clients/middleware/retry/defaultRetryDecider.ts#L19

const errorCode = parsedError?.code;

should be

const errorCode = parsedError?.name;

AWS.Response.code changing to AWS.Response.name was a breaking change in aws sdk v2 => v3.

I confirmed with logging that errorCode is undefined when passed to isClockSkewError(errorCode) and this causes the request to NOT retry. Changing the errorCode value fixes the issue and I stop getting the error "Signature not yet current: 20240329T135554Z is still later than 20240329T134259Z (20240329T133759Z + 5 min"

Expected behavior

Clock skew should be automatically handled starting in amplify v6 (access to DateUtils workaround was removed)

Reproduction steps

  1. Create a react app with API gateway requiring authenticated requests
  2. Set computer local clock to wrong time (off by more than 5 minutes)
  3. Have browser make API request and it fails with "Signature not yet current"

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

cwomack commented 5 months ago

Hey, @jbarnickol 👋. Thanks for opening this issue and it appears to be related to #9281 and #11675. We are investigating this and will follow up with any additional questions, but in the mean time can you take a look at those two other issues to see if they align to what you're experiencing?

erinleigh90 commented 5 months ago

Thank you so much for the thorough investigation and pinpointing the issue! A fix has been released and appears to be working on my side, can you please validate that this issue is fixed for you in the latest version of amplify (aws-amplify@6.0.25)?

jbarnickol commented 5 months ago

@erinleigh90 Thanks for the quick turnaround! I confirmed 6.0.25 fixes the issue 🎉