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

formats/odata: handle bad url-encoded subpaths #1270

Open
wants to merge 5 commits 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
15 changes: 11 additions & 4 deletions lib/formats/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ const getServiceRoot = (subpath) => {

// Given an OData URL subpath, returns a contextStack: [ [ pathName: String, tableId: String? ] ]
// that the subpath represents.
const extractPathContext = (subpath) =>
// we have to slice(1) to drop the first element, due to the leading /.
subpath.split('/').slice(1).map((part) => {
const match = /^([^(]+)\('((?:uuid:)?[a-z0-9-]+)'\)$/i.exec(decodeURIComponent(part));
const extractPathContext = (subpath) => {
const rawParts = subpath.split('/').slice(1);
let parts;
try {
parts = rawParts.map(part => decodeURIComponent(part));
} catch (err) {
throw Problem.user.unparseableODataExpression({ reason: 'URL-decoding failed' });
}
return parts.map((part) => {
const match = /^([^(]+)\('((?:uuid:)?[a-z0-9-]+)'\)$/i.exec(part);
return (match == null) ? [ part, null ] : [ match[1], match[2] ];
});
};

// Given a querystring object, processes the paging information off of it. Always
// computes the requested window (limit/offset) so that the correct nextUrl can be
Expand Down
6 changes: 6 additions & 0 deletions test/unit/formats/odata.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,12 @@ describe('odata message composition', () => {
}).should.be.rejected();
});

it('should reject if subpath cannot be decoded', () =>
fieldsFor(testData.forms.simple).then((fields) => {
const submission = mockSubmission('one', testData.instances.simple.one);
(() => singleRowToOData(fields, submission, 'http://localhost:8989', "/simple.svc/Submissions%ea('one')", {})).should.throw();
}));

// eslint-disable-next-line arrow-body-style
it('should pass if the toplevel table is correct', () => {
return fieldsFor(testData.forms.simple).then((fields) => {
Expand Down