Skip to content

Commit

Permalink
fix(showcase): prevent arbitrary url evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
fpaul-1A committed Jul 16, 2024
1 parent 27d84c4 commit 7b9cffd
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,23 @@
}
],
"status": "available"
},
{
"id": 6,
"category": {
"id": 0,
"name": "otter"
},
"name": "???",
"photoUrls": [
"https://amadeusitgroup.github.io/otter/#/random-url-that-should-never-be-used"
],
"tags": [
{
"id": 0,
"name": "otter"
}
],
"status": "available"
}
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormsModule } from '@angular/forms';
import { DfMedia } from '@design-factory/design-factory';
import { NgbHighlight, NgbPagination, NgbPaginationPages } from '@ng-bootstrap/ng-bootstrap';
import { O3rComponent } from '@o3r/core';
import { OtterPickerPresComponent } from '../../utilities';
import { OtterIconPathPipe, OtterPickerPresComponent } from '../../utilities';

const FILTER_PAG_REGEX = /[^0-9]/g;

Expand All @@ -18,6 +18,7 @@ const FILTER_PAG_REGEX = /[^0-9]/g;
NgbHighlight,
FormsModule,
NgbPagination,
OtterIconPathPipe,
OtterPickerPresComponent,
NgbPaginationPages
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<tr>
<td>
@if (pet.photoUrls?.[0]; as icon) {
<img width="34" height="34" [src]="baseUrl+icon" alt="{{icon}}" />
<img width="34" height="34" [src]="icon | otterIconPath" alt="{{icon}}" />
}
</td>
<th scope="row">
Expand Down
7 changes: 3 additions & 4 deletions apps/showcase/src/components/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export * from './date-picker-input/index';
export * from './otter-picker/index';
export * from './copy-text/index';
export * from './date-picker-input/index';
export * from './date-picker-input-hebrew/index';
export * from './in-page-nav/index';
export * from './otter-picker/index';
export * from './scroll-back-top/index';
export * from './sidenav/index';
export * from './date-picker-input/index';
export * from './date-picker-input-hebrew/index';
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './otter-icon-path.pipe';
export * from './otter-picker-pres.component';

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';
import { OTTER_ICONS } from './otter-icons';

@Pipe({
name: 'otterIconPath',
standalone: true
})
export class OtterIconPathPipe implements PipeTransform {
private readonly BASE_URL = location.href.split('/#', 1)[0];
private readonly ICON_MATCHER = new RegExp(OTTER_ICONS.join('|'));

public transform(value: string) {
const iconPath = this.ICON_MATCHER.test(value) ? value : OTTER_ICONS[0];
return `${this.BASE_URL}${iconPath}`;
}
}
17 changes: 17 additions & 0 deletions apps/showcase/src/components/utilities/otter-picker/otter-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const OTTER_ICONS = [
'/assets/otter.svg',
'/assets/mini-otters/astronotter.svg',
'/assets/mini-otters/bonotter.svg',
'/assets/mini-otters/c3potter.svg',
'/assets/mini-otters/colombotter.svg',
'/assets/mini-otters/djokotter.svg',
'/assets/mini-otters/hallowtter.svg',
'/assets/mini-otters/harry-otter.svg',
'/assets/mini-otters/jack-sparrowtter.svg',
'/assets/mini-otters/mandalotter.svg',
'/assets/mini-otters/mariotter.svg',
'/assets/mini-otters/neotter.svg',
'/assets/mini-otters/pizzaiotter.svg',
'/assets/mini-otters/ronaldotter.svg',
'/assets/mini-otters/sombrerotter.svg'
] as const;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, forwardRef, Input, signal, ViewEnca
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
import { O3rComponent } from '@o3r/core';
import { OTTER_ICONS } from './otter-icons';

@O3rComponent({ componentType: 'Component' })
@Component({
Expand Down Expand Up @@ -29,23 +30,7 @@ export class OtterPickerPresComponent implements ControlValueAccessor {
public selectedOtter = signal('');

/** List of available otters */
public otters = [
'/assets/otter.svg',
'/assets/mini-otters/astronotter.svg',
'/assets/mini-otters/bonotter.svg',
'/assets/mini-otters/c3potter.svg',
'/assets/mini-otters/colombotter.svg',
'/assets/mini-otters/djokotter.svg',
'/assets/mini-otters/hallowtter.svg',
'/assets/mini-otters/harry-otter.svg',
'/assets/mini-otters/jack-sparrowtter.svg',
'/assets/mini-otters/mandalotter.svg',
'/assets/mini-otters/mariotter.svg',
'/assets/mini-otters/neotter.svg',
'/assets/mini-otters/pizzaiotter.svg',
'/assets/mini-otters/ronaldotter.svg',
'/assets/mini-otters/sombrerotter.svg'
];
public otters = OTTER_ICONS;

/** Base URL where the images can be fetched */
public baseUrl = location.href.split('/#', 1)[0];
Expand Down

0 comments on commit 7b9cffd

Please sign in to comment.