sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Request failed, API returned 403

Open TobiasReich opened this issue 6 years ago • 12 comments

Using the new Sentry version for Android

implementation 'io.sentry:sentry-android:3.1.0'

I always get the same error message from my code. And it comes down to CSRF Verification Failed messages

Sentry is configured in that way:

Manifest: <meta-data android:name="io.sentry.auto-init" android:value="false" />

And in the Application class it is calling:

val sentryConfig = Sentry.OptionsConfiguration<SentryAndroidOptions> { options ->
       options.isEnableExternalConfiguration = true
       options.beforeSend = sentryBeforeSendCallback
       options.beforeBreadcrumb = sentryBeforeBreadcrumbCallback
       options.isAttachStacktrace = true
       options.isAttachThreads = true
       options.isDebug = true
       options.dsn = "https://[project dsn]
 }

      SentryAndroid.init(this, sentryConfig) // Set the configuration

In the app project root folder the sentry.properties are

log.level=debug
defaults.url=[url]
defaults.project=[project]
defaults.org=[org]
auth.dsn=https://[android dsn]
auth.token=[token]

In any case, it currently doesn't work. And when starting the app the Android Logcat looks like this (Filtered for "Sentry"):

2020-10-20 13:35:13.497 D/Sentry: Auto-init: false
2020-10-20 13:35:13.497 I/Sentry: Retrieving auto-init from AndroidManifest.xml
2020-10-20 13:35:13.977 I/Sentry: sentry-debug-meta.properties file was not found.
2020-10-20 13:35:13.979 I/Sentry: Initializing SDK with DSN: 'https://[my android dsn]@[sentry host]/36'
2020-10-20 13:35:13.994 D/Sentry: SU doesn't exist.
    java.io.IOException: Cannot run program "/system/xbin/which": error=2, No such file or directory
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
        at java.lang.Runtime.exec(Runtime.java:695)
        at java.lang.Runtime.exec(Runtime.java:560)
        at io.sentry.android.core.util.RootChecker.checkSUExist(RootChecker.java:135)
        at io.sentry.android.core.util.RootChecker.isDeviceRooted(RootChecker.java:90)
        at io.sentry.android.core.DefaultAndroidEventProcessor.loadContextData(DefaultAndroidEventProcessor.java:114)
        at io.sentry.android.core.DefaultAndroidEventProcessor.lambda$new$0$DefaultAndroidEventProcessor(DefaultAndroidEventProcessor.java:102)
        at io.sentry.android.core.-$$Lambda$DefaultAndroidEventProcessor$ZsPdDrAaOs30gov_5eSNgy_KYe8.call(Unknown Source:2)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.io.IOException: error=2, No such file or directory
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
        at java.lang.ProcessImpl.start(ProcessImpl.java:132)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        at java.lang.Runtime.exec(Runtime.java:695) 
        at java.lang.Runtime.exec(Runtime.java:560) 
        at io.sentry.android.core.util.RootChecker.checkSUExist(RootChecker.java:135) 
        at io.sentry.android.core.util.RootChecker.isDeviceRooted(RootChecker.java:90) 
        at io.sentry.android.core.DefaultAndroidEventProcessor.loadContextData(DefaultAndroidEventProcessor.java:114) 
        at io.sentry.android.core.DefaultAndroidEventProcessor.lambda$new$0$DefaultAndroidEventProcessor(DefaultAndroidEventProcessor.java:102) 
        at io.sentry.android.core.-$$Lambda$DefaultAndroidEventProcessor$ZsPdDrAaOs30gov_5eSNgy_KYe8.call(Unknown Source:2) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
2020-10-20 13:35:13.997 I/Sentry: GlobalHubMode: 'true'
2020-10-20 13:35:14.019 D/Sentry: UncaughtExceptionHandlerIntegration enabled: true
2020-10-20 13:35:14.019 D/Sentry: default UncaughtExceptionHandler class='cat.ereza.customactivityoncrash.CustomActivityOnCrash$1'
2020-10-20 13:35:14.020 D/Sentry: UncaughtExceptionHandlerIntegration installed.
2020-10-20 13:35:14.026 D/Sentry: SendCachedEventFireAndForgetIntegration installed.
2020-10-20 13:35:14.026 D/Sentry: NdkIntegration enabled: true
2020-10-20 13:35:14.027 D/Sentry: Started processing cached files from /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry
2020-10-20 13:35:14.027 D/Sentry: Processing dir. /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry
2020-10-20 13:35:14.029 D/Sentry: Processing 0 items from cache dir /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry
2020-10-20 13:35:14.030 D/Sentry: File /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/outbox is not a File.
2020-10-20 13:35:14.030 D/Sentry: File /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/sessions is not a File.
2020-10-20 13:35:14.030 D/Sentry: NdkIntegration installed.
2020-10-20 13:35:14.031 D/Sentry: File /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/.sentry-native is not a File.
2020-10-20 13:35:14.031 D/Sentry: Registering EnvelopeFileObserverIntegration for path: /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/outbox
2020-10-20 13:35:14.031 D/Sentry: Finished processing cached files from /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry
2020-10-20 13:35:14.036 D/Sentry: EnvelopeFileObserverIntegration installed.
2020-10-20 13:35:14.037 D/Sentry: SendCachedEventFireAndForgetIntegration installed.
2020-10-20 13:35:14.037 D/Sentry: AnrIntegration enabled: true
2020-10-20 13:35:14.037 D/Sentry: ANR timeout in milliseconds: 5000
2020-10-20 13:35:14.039 D/Sentry: Started processing cached files from /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/outbox
2020-10-20 13:35:14.040 D/Sentry: Processing dir. /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/outbox
2020-10-20 13:35:14.042 D/Sentry: AnrIntegration installed.
2020-10-20 13:35:14.042 D/Sentry: Processing 0 items from cache dir /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/outbox
2020-10-20 13:35:14.042 D/Sentry: enableSessionTracking enabled: true
2020-10-20 13:35:14.042 D/Sentry: Finished processing cached files from /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/outbox
2020-10-20 13:35:14.042 D/Sentry: enableAppLifecycleBreadcrumbs enabled: true
2020-10-20 13:35:14.046 D/Sentry: AppLifecycleIntegration installed.
2020-10-20 13:35:14.046 D/Sentry: ActivityBreadcrumbsIntegration enabled: true
2020-10-20 13:35:14.047 D/Sentry: ActivityBreadcrumbsIntegration installed.
2020-10-20 13:35:14.047 D/Sentry: AppComponentsBreadcrumbsIntegration enabled: true
2020-10-20 13:35:14.047 D/Sentry: AppComponentsBreadcrumbsIntegration installed.
2020-10-20 13:35:14.047 D/Sentry: SystemEventsBreadcrumbsIntegration enabled: true
2020-10-20 13:35:14.049 D/Sentry: SystemEventsBreadcrumbsIntegration installed.
2020-10-20 13:35:14.049 D/Sentry: enableSystemEventsBreadcrumbs enabled: true
2020-10-20 13:35:14.057 D/Sentry: TempSensorBreadcrumbsIntegration installed.
2020-10-20 13:35:14.058 D/Sentry: enableSystemEventBreadcrumbs enabled: true
2020-10-20 13:35:14.328 I/Sentry: Breadcrumb was dropped by beforeBreadcrumb
2020-10-20 13:35:15.452 D/Sentry: Adding Envelope to offline storage: /data/user/0/com.newsenselab.android.m_sense_migraine/cache/sentry/657d464f-190e-4276-941a-dd585b62995f.envelope
2020-10-20 13:35:15.520 I/Sentry: Breadcrumb was dropped by beforeBreadcrumb
2020-10-20 13:35:15.950 D/Sentry: Request failed, API returned 403
2020-10-20 13:35:15.953 D/Sentry: <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <meta name="robots" content="NONE,NOARCHIVE">
      <meta name="viewport" content="width=device-width, initial-scale=1">
    
      <link href="https://[sentry host]/_static/1603191371/sentry/images/favicon.ico" rel="shortcut icon" type="image/png"/>
    
      <link rel="icon" href="https://[sentry host]/_static/1603191371/sentry/images/logos/apple-touch-icon.png">
      <link rel="apple-touch-icon" href="https://[sentry host]/_static/1603191371/sentry/images/logos/apple-touch-icon.png">
      <link rel="apple-touch-icon" sizes="76x76" href="https://[sentry host]/_static/1603191371/sentry/images/logos/apple-touch-icon-76x76.png">
      <link rel="apple-touch-icon" sizes="120x120" href="https://[sentry host]/_static/1603191371/sentry/images/logos/apple-touch-icon-120x120.png">
      <link rel="apple-touch-icon" sizes="152x152" href="https://[sentry host]/_static/1603191371/sentry/images/logos/apple-touch-icon-152x152.png">
    
      <link rel="mask-icon" sizes="any" href="https://[sentry host]/_static/1603191371/sentry/images/logos/logo-sentry.svg" color="#FB4226">
    
      <link href="/_static/1603191371/sentry/dist/sentry.css" rel="stylesheet"/>
        
      <title>CSRF Verification Failed | Sentry</title>
    
      <script>
        window.__initialData = {"languageCode":"en","csrfCookieName":"sc","features":[],"urlPrefix":"https://[sentry host]","needsUpgrade":false,"privacyUrl":null,"isOnPremise":true,"gravatarBaseUrl":"https://secure.gravatar.com","dsn":"https://[not my android project]@[sentry host]/1","version":{"current":"20.6.0","build":"37a7530206f8407f1127fc8e9bb2fdd99cdffb31","upgradeAvailable":true,"latest":"20.10.1"},"termsUrl":null,"sentryConfig":{"dsn":"https://[not my android project]@[sentry host]/1","release":"37a7530206f8407f1127fc8e9bb2fdd99cdffb31","whitelistUrls":[],"environment":"production"},"apmSampling":0.0,"singleOrganization":true,"user":null,"invitesEnabled":true,"dsn_requests":"","lastOrganization":null,"messages":[],"userIdentity":{"ip_address":"87.122.103.49"},"isAuthenticated":false,"statuspage":null,"supportEmail":"[email protected]","distPrefix":"/_static/1603191371/sentry/dist/"};
      </script>
    
      
      
      <script src="/_static/1603191371/sentry/dist/vendor.js"></script>
      <script src="/_static/1603191371/sentry/dist/app.js" data-entry="true"></script>
    
      <script>
        // if the ads.js file loads below it will mark this variable as false
        window.adblockSuspected = true;
      </script>
      <script src="/_static/1603191371/sentry/js/ads.js"></script>
      
    </head>
    
    <body class=" narrow">
      
      <div class="app">   
        
    <div id="blk_alerts" class="messages-container"></div>
    <script>
    $(function(){
      ReactDOM.render(React.createFactory(SentryApp.SystemAlerts)({
         className: "alert-list"
      }), document.getElementById('blk_alerts'));
    });
    </script>
    <div id="blk_indicators"></div>
    <script>
    $(function(){
      ReactDOM.render(React.createFactory(SentryApp.Indicators)({
         className: "indicators-container"
      }), document.getElementById('blk_indicators'));
    });
    </script>
    
        <div class="container">
          <div class="content">
            
    <div class="pattern-bg"></div>
    <section class="org-login">
      <div class="box box-modal">
        <div class="box-header">
          <a class="logo-with-action" href="/">  
            <span class="icon-sentry-logo-full"></span>
          </a>
        </div>
        <div class="box-content with-padding">
          
        <section class="body">
            <div class="page-header">
                <h2>CSRF Verification Failed</h2>
            </div>
    
            <p>A required security token was not found or was invalid.</p>
    
            <p>If you're continually seeing this issue, try the following:</p>
    
            <ol>
              <li>Clear cookies (at least for Sentry's domain).</li>
              <li>Reload the page you're trying to submit
2020-10-20 13:35:15.955 D/Sentry: The transport failed to send the envelope with response code 403
2020-10-20 13:35:15.956 E/Sentry: Envelope submission failed
    java.lang.IllegalStateException: The transport failed to send the envelope with response code 403
        at io.sentry.transport.AsyncConnection$EnvelopeSender.flush(AsyncConnection.java:249)
        at io.sentry.transport.AsyncConnection$EnvelopeSender.run(AsyncConnection.java:212)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
        ...

TobiasReich avatar Oct 20 '20 12:10 TobiasReich

hey @TobiasReich thanks for raising this.

isEnableExternalConfiguration is not needed for Android, this is meant for server conf.

not sure if it's the case, but are you using Sentry on-premise? if so: https://github.com/getsentry/sentry-java/releases/tag/3.0.0

read the notes about Note for Sentry On Premise users:

This version uses the envelope endpoint. If you are using an on-premise installation it requires Sentry version >= v20.6.0 to work. If you are using sentry.io nothing will change and no action is needed.

is that the case? thanks

marandaneto avatar Oct 20 '20 13:10 marandaneto

I met the same problem with spring-boot-starter.

springboot version 2.1.0 sentry-spring-boot-starter 3.0.0 ~ 3.1.1 sentry-logback 3.0.0 ~ 3.1.1 sentry server 8.19.0

INFO: Session is null on scope.withSession
ERROR: Request failed, API returned 403
ERROR: Envelope submission failed 
 java.util.UnknownFormatConversionException: Conversion = ';'
java.util.UnknownFormatConversionException: Conversion = ';'
	at java.util.Formatter.checkText(Formatter.java:2579)
	at java.util.Formatter.parse(Formatter.java:2555)
	at java.util.Formatter.format(Formatter.java:2501)
	at java.util.Formatter.format(Formatter.java:2455)
	at java.lang.String.format(String.java:2940)
	at io.sentry.SystemOutLogger.log(SystemOutLogger.java:20)
	at io.sentry.DiagnosticLogger.log(DiagnosticLogger.java:53)
	at io.sentry.transport.HttpTransport.readAndLog(HttpTransport.java:285)
	at io.sentry.transport.HttpTransport.send(HttpTransport.java:263)
	at io.sentry.transport.AsyncConnection$EnvelopeSender.flush(AsyncConnection.java:239)
	at io.sentry.transport.AsyncConnection$EnvelopeSender.run(AsyncConnection.java:212)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
	at java.util.concurrent.FutureTask.run(FutureTask.java)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)`


DEBUG: Capturing event: c44094f7078c4001a2d30bef0345f6b9
ERROR: Request failed, API returned 403
ERROR: Envelope submission failed 
 java.util.UnknownFormatConversionException: Conversion = ';'

Then I add a configuration.

@Configuration
public class SentryConfig implements InitializingBean {
    @Autowired IHub hub;
    @Override
    public void afterPropertiesSet() throws Exception {
        hub.startSession();
    }
}

output:

DEBUG: Capturing event: c44094f7078c4001a2d30bef0345f6b9
ERROR: Request failed, API returned 403
ERROR: Envelope submission failed 
 java.util.UnknownFormatConversionException: Conversion = ';'
java.util.UnknownFormatConversionException: Conversion = ';'
	at java.util.Formatter.checkText(Formatter.java:2579)
	at java.util.Formatter.parse(Formatter.java:2555)
	at java.util.Formatter.format(Formatter.java:2501)
	at java.util.Formatter.format(Formatter.java:2455)
	at java.lang.String.format(String.java:2940)
	at io.sentry.SystemOutLogger.log(SystemOutLogger.java:20)
	at io.sentry.DiagnosticLogger.log(DiagnosticLogger.java:53)
	at io.sentry.transport.HttpTransport.readAndLog(HttpTransport.java:285)
	at io.sentry.transport.HttpTransport.send(HttpTransport.java:263)
	at io.sentry.transport.AsyncConnection$EnvelopeSender.flush(AsyncConnection.java:239)
	at io.sentry.transport.AsyncConnection$EnvelopeSender.run(AsyncConnection.java:212)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
	at java.util.concurrent.FutureTask.run(FutureTask.java)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

doyard avatar Oct 21 '20 01:10 doyard

@chamhaw it's not a bug, at least in your case, you must upgrade your Sentry server as stated: https://github.com/getsentry/sentry-java/issues/1001#issuecomment-712854444

marandaneto avatar Oct 21 '20 06:10 marandaneto

Okay, we just updated to Sentry 20.10.1 78833d9 but the issue is still there. We gonna have a look at the docker-compose.yml there seem to be some changes needed now. I will give more info as soon as I know something. Thanks!

TobiasReich avatar Oct 21 '20 07:10 TobiasReich

Closing the issue, as it seems like the original issue has been resolved. Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it. Cheers!

marandaneto avatar Oct 21 '20 09:10 marandaneto

@marandaneto I'm having the same error. Our server is running version Sentry 20.7.0.dev0 cc9f7d1 (on prem). On client side, I'm using Android version 3.1.2.

"This version uses the envelope endpoint. If you are using an on-premise installation it requires Sentry version >= v20.6.0 to work. If you are using sentry.io nothing will change and no action is needed."

So the server version we're using should be good right? When I downgraded the Android version to 2.3.2, it works. But I don't want to run an older version of the library. Any ideas on what can be done to solve this?

ArmanIzad avatar Nov 05 '20 03:11 ArmanIzad

would you mind updating to the latest version? https://github.com/getsentry/sentry/releases/tag/20.10.1 or to open an issue directly on https://github.com/getsentry/sentry with logs etc? cus the SDK seems to work normally. @ArmanIzad also enable the SDK on debug mode and copy-paste some logs just to be sure the issue is the same, thanks

marandaneto avatar Nov 12 '20 08:11 marandaneto

Another team is handling the server side, the only access I have is as a developer. Just in case anyone else encounter this issue, we managed to get this to work with these client versions: Sentry Android SDK version 2.3.2 Sentry Android gradle plugin version 1.7.34 Sentry iOS SDK version 5.2.2

ArmanIzad avatar Nov 12 '20 08:11 ArmanIzad

@marandaneto I'm facing the same issue while integrating to vertx demo app. I have added the DSN keys and followed the docs but nothing is being registered in the sentry and it says that failed to send the envelope.

Sentry version: 4.3.0 vertx version : 4.0.0

srujana121 avatar Apr 05 '21 22:04 srujana121

@srujana121 could you please publish on github a complete sample application that reproduces this issue?

maciejwalkowiak avatar Apr 06 '21 07:04 maciejwalkowiak

@maciejwalkowiak Hi, I can't publish the details since it's private software. I can maybe provide more details about the error if need be. Sorry for the miscommunication, by the demo I didn't mean a sample application.

srujana121 avatar Apr 06 '21 07:04 srujana121

@srujana121 this issue is related to an Android App, as you use vertex, I'd recommend you open a new issue with full detail log.

answering questions like, do you use Sentry.io or on-premise? which version? Also, take a look at your Gson dependency, there's a note about it here https://docs.sentry.io/platforms/java/#install

Let's continue it from there, thanks

marandaneto avatar Apr 06 '21 08:04 marandaneto