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

check for api/catalog calls, dont add base path for them #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Check for requests starting with `api/catalog` and don't change base path for them.
- VtexIdclientAutCookie header.


## [0.0.5] - 2019-04-26

Expand Down
7 changes: 7 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
"path": "/{{account}}/search/*"
}
},
{
"name": "outbound-access",
"attrs": {
"host": "portal.vtexcommercestable.com.br",
"path": "/api/catalog/*"
}
},
{
"name": "colossus-write-logs"
}
Expand Down
4 changes: 3 additions & 1 deletion node/handlers/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export const catalog = async (ctx: Context) => {

// The `portal-search` API has an incorrect endpoint /buscaautocomplete on root.
const isAutoComplete = (path as string).startsWith('buscaautocomplete')
const isNewCatalog = (path as string).startsWith('api/catalog/')

const [host, basePath] = isGoCommerce
? ['api.gocommerce.com', `${account}/search`]
: ['portal.vtexcommercestable.com.br', isAutoComplete ? '' : 'api/catalog_system']
: ['portal.vtexcommercestable.com.br', isAutoComplete || isNewCatalog ? '' : 'api/catalog_system']

const cookie = segmentToken && {Cookie: `vtex_segment=${segmentToken}`}
const params = {
Expand All @@ -32,6 +33,7 @@ export const catalog = async (ctx: Context) => {
'Authorization': authToken,
'Proxy-Authorization': authToken,
'User-Agent': process.env.VTEX_APP_ID,
VtexIdclientAutCookie: authToken,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow! That's not safe at all - you're adding this app's token to communicate with an API, yet we have no idea what permissions the actual caller had. Why did you have to send this header? This might effectively make a private API public, through this proxy, if this app has sufficient permissions.

... operationId ? {'x-vtex-operation-id': operationId} : null,
...cookie,
},
Expand Down
2 changes: 1 addition & 1 deletion node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3087,7 +3087,7 @@ static-extend@^0.1.1:
define-property "^0.2.5"
object-copy "^0.1.0"

"stats-lite@github:vtex/node-stats-lite#dist":
stats-lite@vtex/node-stats-lite#dist:
version "2.2.0"
resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797"
dependencies:
Expand Down