-
Notifications
You must be signed in to change notification settings - Fork 45
isom-2008 feat(redirect): enhance checks for bypassing transition page #2401
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
isom-2008 feat(redirect): enhance checks for bypassing transition page #2401
Conversation
|
bugbot run |
…ct behavior for ogUrl matches
fixed tests in 29b40c8 |
fixed in 9206094 |
| } | ||
|
|
||
| const isFromTrustedPage = referrer.startsWith(ogUrl) | ||
| const isFromTrustedPage = RedirectService.isFromTrustedPage(referrer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: should use this instead of RedirectService
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually im not super familiar with the framework, but i referenced this from an existing code
GoGovSG/src/server/modules/redirect/services/RedirectService.ts
Lines 47 to 49 in 2d94333
| if (RedirectService.isValidShortUrl(rawShortUrl)) { | |
| throw new NotFoundError('Invalid Url') | |
| } |
GoGovSG/src/server/modules/redirect/services/RedirectService.ts
Lines 98 to 100 in 2d94333
| private static isValidShortUrl(shortUrl: string): boolean { | |
| return !shortUrl || !/^[a-zA-Z0-9-]+$/.test(shortUrl) | |
| } |
curious - what's the issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah oops sorry was reviewing on mobile, so didn't see the static part. Doing RedirectService.isFromTrustedPage is ok since isFromTrustedPage is a static function. If otherwise then should use this.
| ) | ||
| }) | ||
|
|
||
| describe('referrer validation', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can name it after the function instead? Easier to identify and debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in 36b91b0 👍
| redirectService = new RedirectService( | ||
| mockUrlRepository as unknown as UrlRepositoryInterface, | ||
| mockCrawlerCheckService as unknown as CrawlerCheckService, | ||
| mockCookieArrayReducerService as unknown as CookieArrayReducerService, | ||
| mockLinkStatisticsService as unknown as LinkStatisticsService, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I think this init can be outside of the beforeEach and describe, might help in making tests run a bit faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in 1684f26 👍
…irectService tests
…ity and organization
| } | ||
|
|
||
| const isFromTrustedPage = referrer.startsWith(ogUrl) | ||
| const isFromTrustedPage = RedirectService.isFromTrustedPage(referrer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah oops sorry was reviewing on mobile, so didn't see the static part. Doing RedirectService.isFromTrustedPage is ok since isFromTrustedPage is a static function. If otherwise then should use this.
Problem
What problem are you trying to solve? What issue does this close?
Closes https://linear.app/ogp/issue/ISOM-2008/vapt-insufficient-referrer-validation-bypasses-transition-page
Solution
How did you solve the problem?
Improvements:
URLfunction to check instead ofstartsWithTests
What tests should be run to confirm functionality?