balderdashy / balderdashy/sails

req.wantsJson logic is not robust, leads to errors in SEO

Open
#7,239 8 comments 0 reactions 0 assignees View on GitHub
does this answer your question?
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Node version**: 14.20.0
**Sails version** _(sails)_: 1.5.2


`req.wantsJson` logic is not robust as it returns true when `accept` header is `*/*` and has no `content-type` or `x-requested-with`.
This leads to error in SEO when I use this property to return json vs html. In the case (`accept: */*`), what search engine crawlers use, they expect html. But as wantsJson is true, my code returns json.

We could overcome this if we default wantsJson to false when it is not clear whether requested resource is json or not.

Contributor guide

Open the contributing guide

Research direction

Start by tracing how Sails determines req.wantsJson from the Accept, Content-Type, and X-Requested-With headers. Reproduce the reported case with Accept: */* and no other indicators, then inspect existing tests around this request behavior. Done means the agreed handling of ambiguous requests is implemented and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.