Skip to content

Commit

Permalink
Merge pull request #573 from DataDog/louiszawadzki/rum-2507/prevent-l…
Browse files Browse the repository at this point in the history
…oop-for-expo

Add 127.0.0.1 in the list of dev resources
  • Loading branch information
louiszawadzki authored Dec 20, 2023
2 parents 3c34d26 + b6a5747 commit 6b321db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const resourceMockFactory = new ResourceMockFactory();

describe('internalDevResourceBlocklist', () => {
describe('filterDevResource', () => {
it.each(['192.168.1.20', '10.46.29.155', '172.28.1.20'])(
it.each(['192.168.1.20', '10.46.29.155', '172.28.1.20', '127.0.0.1'])(
'returns null when a expo logs call with ip %s is made',
ip => {
const resource = resourceMockFactory.getCustomResource({
Expand All @@ -25,15 +25,15 @@ describe('internalDevResourceBlocklist', () => {
expect(filterDevResource(resource)).toBeNull();
}
);
it('returns null when an expo logs call with custom port is made', () => {
it('returns the event when an expo logs call with custom port is made', () => {
const resource = resourceMockFactory.getCustomResource({
request: {
method: 'GET',
url: 'http://10.46.29.155:19000/logs',
kind: 'xhr'
}
});
expect(filterDevResource(resource)).toBeNull();
expect(filterDevResource(resource)).not.toBeNull();
});
it('returns null when a rn symbolicate call is made', () => {
const resource = resourceMockFactory.getCustomResource({
Expand All @@ -45,15 +45,15 @@ describe('internalDevResourceBlocklist', () => {
});
expect(filterDevResource(resource)).toBeNull();
});
it('returns null when an rn symbolicate call with custom port is made', () => {
it('returns the event when an rn symbolicate call with custom port is made', () => {
const resource = resourceMockFactory.getCustomResource({
request: {
method: 'GET',
url: 'http://localhost:40/symbolicate',
kind: 'xhr'
}
});
expect(filterDevResource(resource)).toBeNull();
expect(filterDevResource(resource)).not.toBeNull();
});
it('returns the resource when the resource is not a dev resource', () => {
const resource = resourceMockFactory.getCustomResource({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import type { RUMResource } from '../../interfaces/RumResource';
* An example URL is http://192.168.1.20:8081/logs or http://10.46.29.155:19000/logs
*/
const EXPO_DEV_LOGS_REGEX = new RegExp(
'^http://((10|172|192).[0-9]+.[0-9]+.[0-9]+|localhost):[0-9]+/logs$'
'^http://((10|172|192).[0-9]+.[0-9]+.[0-9]+|localhost|127.0.0.1):808[0-9]/logs$'
);

/**
* This call is made every time the RN packager reloads the js in dev mode.
*/
const RN_PACKAGER_SYMBOLICATE_REGEX = new RegExp(
'^http://localhost:[0-9]+/symbolicate$'
'^http://localhost:808[0-9]/symbolicate$'
);

const internalResourceBlocklist: RegExp[] = [
const internalDevResourceBlocklist: RegExp[] = [
EXPO_DEV_LOGS_REGEX,
RN_PACKAGER_SYMBOLICATE_REGEX
];
Expand All @@ -38,12 +38,11 @@ const internalResourceBlocklist: RegExp[] = [
export const filterDevResource = (
resource: RUMResource
): RUMResource | null => {
// TODO: if we get the confirmation by Expo that the
// logs call is only made when __DEV__ is true, add an
// early return for when it is false.
for (const resourceRegex of internalResourceBlocklist) {
if (resourceRegex.test(resource.request.url)) {
return null;
if (__DEV__) {
for (const resourceRegex of internalDevResourceBlocklist) {
if (resourceRegex.test(resource.request.url)) {
return null;
}
}
}
return resource;
Expand Down

0 comments on commit 6b321db

Please sign in to comment.