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

Malformed URLs throw an error when parsing snaplinks #249

Open
jonathonherbert opened this issue Jun 17, 2021 · 0 comments
Open

Malformed URLs throw an error when parsing snaplinks #249

jonathonherbert opened this issue Jun 17, 2021 · 0 comments

Comments

@jonathonherbert
Copy link
Contributor

Problem

When the client encounters a malformed URL in a snap link, it throws an error. This recently caused a problem where the accidental inclusion of a javascript bookmarklet in a collection caused a front to fail to press.

java.net.URISyntaxException: Illegal character in opaque part at index 22: javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://dashboard.ophan.co.uk/assets/js/heatmap-bookmarklet.js';})();
	at java.net.URI$Parser.fail(URI.java:2847)
	at java.net.URI$Parser.checkChars(URI.java:3020)
	at java.net.URI$Parser.parse(URI.java:3057)
	at java.net.URI.<init>(URI.java:588)
	at com.gu.facia.api.contentapi.ContentApi$.toIdAndUri$1(ContentApi.scala:119)
	at com.gu.facia.api.contentapi.ContentApi$.$anonfun$linkSnapBrandingsByEdition$5(ContentApi.scala:130)
	at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:273)
	at scala.collection.Iterator.foreach(Iterator.scala:943)
	at scala.collection.Iterator.foreach$(Iterator.scala:943)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
	at scala.collection.IterableLike.foreach(IterableLike.scala:74)
	at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:56)
	at scala.collection.TraversableLike.map(TraversableLike.scala:273)
	at scala.collection.TraversableLike.map$(TraversableLike.scala:266)
	at scala.collection.AbstractTraversable.map(Traversable.scala:108)
	at com.gu.facia.api.contentapi.ContentApi$.linkSnapBrandingsByEdition(ContentApi.scala:130)
	at com.gu.facia.api.FAPI$.getLinkSnapBrandings(FAPI.scala:134)
	at com.gu.facia.api.FAPI$.getLiveLinkSnapBrandingsForCollection(FAPI.scala:120)
	at com.gu.facia.api.FAPI$.$anonfun$liveCollectionContentWithSnaps$2(FAPI.scala:159)
	at com.gu.facia.api.Response.$anonfun$flatMap$1(Response.scala:13)
	at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:307)
	at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41)
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
	at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
	at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:92)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:85)
	at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:92)
	at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
	at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:49)
	at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
	at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
	at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
	at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

A solution

Proceeding on the assumption that it's better to trim invalid content and proceed with parsing the response than failing fast at this point in the pipeline, one solution would be to catch this error and drop the offending snap link from the collection instead.

If that assumption is correct, let's log a warning for visibility. We can make a corresponding change in the Fronts tool to make it harder (hopefully: impossible) for users to add invalid links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant