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

fix(showcase): prevent arbitrary url evaluation #1955

Merged
merged 1 commit into from
Jul 17, 2024
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
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,15 @@
import { Pipe, PipeTransform } from '@angular/core';
import { isOtterIcon, OTTER_ICONS } from './otter-icons';

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

/** @inheritDoc */
public transform(value: string) {
fpaul-1A marked this conversation as resolved.
Show resolved Hide resolved
return `${this.BASE_URL}${isOtterIcon(value) ? value : OTTER_ICONS[0]}`;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** List of icons proposed by the otter-picker */
export const OTTER_ICONS = [
fpaul-1A marked this conversation as resolved.
Show resolved Hide resolved
'/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;

/**
* Check if the given path corresponds to an icon proposed by the otter-picker
* @param path
*/
export const isOtterIcon = (path: string): path is typeof OTTER_ICONS[number] => {
return OTTER_ICONS.includes(path as typeof OTTER_ICONS[number]);
};
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
2 changes: 1 addition & 1 deletion packages/@o3r/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"jsonc-eslint-parser": "~2.4.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-jest": "~28.6.0",
"eslint-plugin-jsdoc": "~48.5.0",
"eslint-plugin-jsdoc": "~48.7.0",
"eslint-plugin-prefer-arrow": "~1.2.3",
"eslint-plugin-unicorn": "^54.0.0",
"jest": "~29.7.0",
Expand Down
Loading