Explorar el Código

Merge pull request #484 from sharelatex/ho-rate-limit-compiles

added rate limit to compile endpoint
Henry Oswald hace 9 años
padre
commit
efe5e9efb0

+ 7 - 1
services/web/app/coffee/router.coffee

@@ -111,7 +111,13 @@ module.exports = class Router
 		webRouter.post '/project/:Project_id/settings', AuthorizationMiddlewear.ensureUserCanWriteProjectSettings, ProjectController.updateProjectSettings
 		webRouter.post '/project/:Project_id/settings/admin', AuthorizationMiddlewear.ensureUserCanAdminProject, ProjectController.updateProjectAdminSettings
 
-		webRouter.post '/project/:Project_id/compile', AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.compile
+		webRouter.post '/project/:Project_id/compile', RateLimiterMiddlewear.rateLimit({
+			endpointName: "compile-project-http"
+			params: ["Project_id"]
+			maxRequests: 800
+			timeInterval: 60 * 60
+		}), AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.compile
+
 		webRouter.post '/project/:Project_id/compile/stop', AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.stopCompile
 
 		# Used by the web download buttons, adds filename header

+ 4 - 0
services/web/app/views/project/editor/pdf.pug

@@ -328,6 +328,10 @@ div.full-size.pdf(ng-controller="PdfController")
 			.alert.alert-danger(ng-show="pdf.compileTerminated")
 				strong #{translate("terminated")}. 
 				span #{translate("compile_terminated_by_user")}
+			
+			.alert.alert-danger(ng-show="pdf.rateLimited")
+				strong #{translate("pdf_compile_rate_limit_hit")} 
+				span #{translate("project_flagged_too_many_compiles")}
 
 			.alert.alert-danger(ng-show="pdf.timedout")
 				p

+ 3 - 1
services/web/public/coffee/ide/pdf/controllers/PdfController.coffee

@@ -388,7 +388,9 @@ define [
 					$scope.pdf.view = "pdf"
 					$scope.pdf.compiling = false
 					parseCompileResponse(data)
-				.error () ->
+				.error (err, status) ->
+					if status == 429
+						$scope.pdf.rateLimited = true
 					$scope.pdf.compiling = false
 					$scope.pdf.renderingError = false
 					$scope.pdf.error = true