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

Validate host/path pattern in Create Route form #2383

Merged
merged 3 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Validate host/path pattern in Create route form
  • Loading branch information
Irfan Habib committed Jun 13, 2018
commit dd7149ca04bc99f951561e722003af450a435853
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
<div>
<mat-form-field>
<input matInput formControlName="host" placeholder="Host" required>
<mat-error *ngIf="addHTTPRoute.controls['host'].errors?.pattern">Invalid Hostname</mat-error>
</mat-form-field>
</div>
<div>
<mat-form-field>
<input matInput formControlName="path" placeholder="Path">
<mat-error *ngIf="addHTTPRoute.controls['path'].errors?.pattern">Invalid Path</mat-error>
</mat-form-field>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { Domain } from '../../../../store/types/domain.types';
import { Route, RouteMode } from '../../../../store/types/route.types';
import { ApplicationService } from '../../application.service';


const hostPattern = '(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct - it allows lots of invalid characters - e.g. /, % etc - see: https://en.wikipedia.org/wiki/Hostname for a simple explanation of what is allowed.

const pathPattern = `^((\/)${hostPattern}?(\/)*)*$`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the path allows more chars than the host. See: https://tools.ietf.org/html/rfc3986#section-3.3 and https://tools.ietf.org/html/rfc3986#appendix-A

@Component({
selector: 'app-add-routes',
templateUrl: './add-routes.component.html',
Expand Down Expand Up @@ -76,9 +77,9 @@ export class AddRoutesComponent implements OnInit, OnDestroy {

ngOnInit() {
this.addHTTPRoute = new FormGroup({
host: new FormControl('', [<any>Validators.required]),
host: new FormControl('', [<any>Validators.required, Validators.pattern(hostPattern)]),
domain: new FormControl('', [<any>Validators.required]),
path: new FormControl('')
path: new FormControl('', [Validators.pattern(pathPattern)])
});
this.addRouteMode = this.addRouteModes[0];

Expand Down