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

💥[RUMF-1152] sanitize resource method names #2288

Merged
merged 1 commit into from
Jun 7, 2023
Merged
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: 3 additions & 1 deletion packages/core/src/browser/fetchObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('fetch proxy', () => {
fetchStub(new Request(FAKE_URL, { method: 'PUT' }), { method: 'POST' }).resolveWith({ status: 500 })
fetchStub(new Request(FAKE_URL), { method: 'POST' }).resolveWith({ status: 500 })
fetchStub(FAKE_URL, { method: 'POST' }).resolveWith({ status: 500 })
fetchStub(FAKE_URL, { method: 'post' }).resolveWith({ status: 500 })
fetchStub(null as any).resolveWith({ status: 500 })
fetchStub({ method: 'POST' } as any).resolveWith({ status: 500 })

Expand All @@ -123,8 +124,9 @@ describe('fetch proxy', () => {
expect(requests[3].method).toEqual('POST')
expect(requests[4].method).toEqual('POST')
expect(requests[5].method).toEqual('POST')
expect(requests[6].method).toEqual('GET')
expect(requests[6].method).toEqual('POST')
expect(requests[7].method).toEqual('GET')
expect(requests[8].method).toEqual('GET')
done()
})
})
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/browser/fetchObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function createFetchObservable() {
}

function beforeSend(observable: Observable<FetchContext>, input: unknown, init?: RequestInit) {
const method = (init && init.method) || (input instanceof Request && input.method) || 'GET'
const methodFromParams = (init && init.method) || (input instanceof Request && input.method)
const method = methodFromParams ? methodFromParams.toUpperCase() : 'GET'
const url = input instanceof Request ? input.url : normalizeUrl(String(input))
const startClocks = clocksNow()

Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/browser/xhrObservable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ describe('xhr observable', () => {
})
})

it('should sanitize request method', (done) => {
withXhr({
setup(xhr) {
xhr.open('get', '/ok')
xhr.send()
xhr.complete(200, 'ok')
},
onComplete() {
const request = requests[0]
expect(request.method).toBe('GET')
done()
},
})
})

it('should track client error', (done) => {
withXhr({
setup(xhr) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/xhrObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function createXhrObservable() {
function openXhr(this: XMLHttpRequest, method: string, url: string | URL | undefined | null) {
xhrContexts.set(this, {
state: 'open',
method,
method: method.toUpperCase(),
url: normalizeUrl(String(url)),
})
}
Expand Down